package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.xmy.cultivate.entity.AuthAdminContent;
import com.xmy.cultivate.entity.CancellationRate;
import com.xmy.cultivate.entity.RecordCourse;
import com.xmy.cultivate.entity.ResidueStudent;
import com.xmy.cultivate.entity.response.ArrivalRate;
import com.xmy.cultivate.entity.response.RepairLessonRs;
import com.xmy.cultivate.entity.views.LeadDataRs;
import com.xmy.cultivate.entity.views.RecordCourseTiny;
import com.xmy.cultivate.entity.views.StudentClassLogRep;
import com.xmy.cultivate.respons.AssignMoney;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 记止课 Mapper 接口
 * </p>
 *
 * @author baomidou
 * @since 2022-08-10
 */
@Mapper
public interface RecordCourseMapper extends BaseMapper<RecordCourse> {
    @Select("select * from record_course where scheduling_detail_id = #{schedulingId} and student_id = #{studentId} limit 0,1")
    public abstract RecordCourseTiny getListForSchedulingIdAndStuId(@Param("schedulingId") Long schedulingId, @Param("studentId") Long studentId);

    /**
     * 请假未补的数量,不包含请假已扣金额的数据
     */
    @Select("select count(id) as count from record_course where student_id = ${studentId} and school_id = ${schoolId} and deleted = 0 and year_part = ${yearPart} and `quarter` = ${quarterNum} and lesson_type =${lessonType} and subjects_id =${subjectsId} and `status` =2 and is_repair<>1 and is_deduct_money =0")
    public abstract Integer getLackCount(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("schoolId") Long schoolId, @Param("studentId") Long studentId, @Param("subjectsId") Long subjectsId, @Param("lessonType") Integer lessonType);

    @Select("select name from organization where id = #{school_id}")
    public abstract String getSchoolName(@Param("school_id") String schoolId);

    @Select({"<script>",
            "<if test= 'type == 6 '>",
            "SELECT",
            "IFNULL( t2.ShouldCount, 0 ) AS ShouldCount,",
            "IFNULL( t2.AlreadyCount, 0 ) AS AlreadyCount,",
            "IFNULL( t2.NotCount, 0 ) AS NotCount,",
            "IFNULL( t2.NotAlreadyBuckleCount, 0 ) AS NotAlreadyBuckleCount,",
            "IFNULL( t2.NotAlreadyNotBuckleCount, 0 ) AS NotAlreadyNotBuckleCount,",
            "IFNULL( t2.NowAlreadyCount, 0 ) AS NowAlreadyCount,",
            "t1.school_id,",
            "t1.pid AS schoolPid,",
            "t1.school_name ",
            "FROM ",
            "( SELECT * FROM school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t1",
            "LEFT JOIN ( ",
            "</if>",
            "SELECT t01.school_id,t01.teacher_id,t01.teacher_name,t01.school_name,t02.year_class_id,t02.course_type_id,",
            "<if test= 'type == 6 '>",
            "COUNT( CASE WHEN t01.STATUS = 2 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS ShouldCount,",

            "COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time &lt;= #{endDate} ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS AlreadyCount,",

            "COUNT( CASE WHEN t01.STATUS = 2  ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) - COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time &lt;= #{endDate} ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS NotCount,",

            "COUNT( CASE WHEN t01.STATUS = 2 AND is_repair &lt;&gt; 1 AND is_deduct_house = 1 AND is_deduct_money = 1 AND buckle_class_house &gt; 0 ",// 未补已扣
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS NotAlreadyBuckleCount, ",

            "COUNT( CASE WHEN t01.STATUS = 2 AND is_repair &lt;&gt; 1 AND buckle_class_money = 0 ",// 未补未扣
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS NotAlreadyNotBuckleCount,",

            "COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time BETWEEN #{startDate} AND #{endDate} ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS NowAlreadyCount",
            "</if>",
            "<if test= 'type != 6 '>",
            "COUNT( CASE WHEN t01.STATUS = 2 THEN 1 END ) AS ShouldCount,",
            "COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time &lt;= #{endDate} THEN 1 END ) AS AlreadyCount,",
            "COUNT( CASE WHEN t01.STATUS = 2 THEN 1 END ) - COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time &lt;= #{endDate} THEN 1 END ) AS NotCount,",
            "COUNT( CASE WHEN t01.STATUS = 2 AND is_repair &lt;&gt; 1 AND is_deduct_house = 1 AND is_deduct_money = 1 AND buckle_class_house &gt; 0 THEN 1 END ) AS NotAlreadyBuckleCount,",// 未补已扣
            "COUNT( CASE WHEN t01.STATUS = 2 AND is_repair &lt;&gt; 1 AND buckle_class_money = 0 THEN 1 END ) AS NotAlreadyNotBuckleCount,",// 未补未扣
            "COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time BETWEEN #{startDate} AND #{endDate} THEN 1 END ) AS NowAlreadyCount ",
            "</if>",
            "FROM",
            "record_course AS t01 ",
            "LEFT JOIN grade AS t02 ON t01.old_grade_id = t02.id ",
            "LEFT JOIN repair_course AS t03 ON t01.repair_id = t03.id ",
            "WHERE ",
            "t01.is_deduct_house &lt;&gt; 3  ",
            "AND t01.deduct_type &lt;&gt; 4 ",
            "AND t01.year_part = ${yearPart} ",
            "AND t01.QUARTER = ${quarterNum} ",
            "AND t01.created_at &lt;= #{endDate} ",
            "AND t01.STATUS = 2 ",
            "AND ((t01.deleted = 0 ) OR ( t01.deleted = 1 AND t01.deleted_at &gt;= #{endDateTimeBefore})) ",
            "<if test= 'type != 6 '>",

            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---

            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "AND t01.`teacher_id` = ${teacherId} ",
            "</when>",
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "</if>",
            "<when test='lessonType!=null and lessonType!=&apos;&apos;'>",
            "AND t01.`lesson_type` = ${lessonType} ",
            "</when>",
            "<if test= 'type == 3'>",
            "and t01.teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
            "</if>",
            "GROUP BY",
            "<if test= 'type == 1 or type == 3'>",
            "teacher_id",
            "</if>",
            "<if test= 'type == 2'>",
            "school_id,teacher_id",
            "</if>",
            "<if test= 'type == 4 or type == 6 '>",
            "school_id",
            "</if>",
            "<if test= 'type == 6 '>",
            ") AS t2 ON t1.school_id = t2.school_id",
            "</if>",
            "</script>"})
    public abstract List<CancellationRate> cancellationRate(@Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate, @Param("lessonType") String lessonType, @Param("yearClassId") String yearClassId, @Param("classTypeIdStr") String classTypeIdStr, @Param("endDateTimeBefore") String endDateTimeBefore, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("teacherId") String teacherId, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    /**
     * 请假补课率详情
     *
     * @param detailType        1总已补 2未补 3已补
     * @param endDateTimeBefore 前一天的时间
     */
    @Select({"<script>",
            "SELECT t01.student_name,t01.teacher_name,t02.`name` AS grade_name,t02.course_type_id,t01.repair_end_date_time,t03.time_start,t03.time_end,t01.lesson_num,t01.year_class_id,getDictName(t01.year_class_id, 14)  as year_class_name",
            "FROM",
            "record_course AS t01",
            "LEFT JOIN grade AS t02 ON t01.old_grade_id = t02.id ",
            "LEFT JOIN repair_course AS t03 ON t01.repair_id = t03.id ",
            "WHERE",
            "t01.is_deduct_house &lt;&gt; 3  ",
            "AND t01.deduct_type &lt;&gt; 4 ",
            "AND t01.year_part = ${yearPart} ",
            "AND t01.QUARTER = ${quarterNum} ",
            "AND t01.created_at &lt;= #{endDate} ",
            "AND t01.STATUS = 2 ",
            "AND ((t01.deleted = 0 ) OR ( t01.deleted = 1 AND t01.deleted_at &gt;= #{endDateTimeBefore})) ",
            "<when test='lessonType!=null and lessonType!=&apos;&apos;'>",
                "AND t01.`lesson_type` = ${lessonType} ",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
                "AND t01.old_grade_id = ${gradeId}",
            "</when>",
            "<if test= 'detailType == 1'>",
                "AND t01.is_repair = 1 ",
                "AND t01.repair_end_date_time &lt;= #{endDate} ",
            "</if>",
            "<if test= 'detailType == 2'>",
                "AND t01.is_repair IN (0,2)",
            "</if>",
            "<if test= 'detailType == 3'>",
                "AND t01.is_repair = 1 ",
                "AND t01.repair_end_date_time BETWEEN #{startDate} AND #{endDate} ",
            "</if>",
            "<if test= 'detailType == 4'>",// 未补已扣
                "AND is_repair &lt;&gt; 1 AND is_deduct_house = 1 AND is_deduct_money = 1 AND buckle_class_house > 0 ",
            "</if>",
            "<if test= 'detailType == 5'>",// 未补未扣
                "AND is_repair &lt;&gt; 1 AND buckle_class_money = 0 ",
            "</if>",

            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "t02.year_class_id in(${authAdminContent.yearClassIds})",
            "and t01.subjects_id in(${authAdminContent.subjectsIds})",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and t02.year_class_id in (${yearClassId})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t01.teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND t01.school_id IN (${schoolId}) ",
            "</when>",
            ") OR (",
            " t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
            // ---权限数据结束---

            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
                "AND t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
                "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "</script>"})
    public abstract IPage<CancellationRate> cancellationRateDetail(IPage<?> iPage, @Param("schoolId") String schoolId, @Param("teacherId") Long teacherId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("subjectsId") String subjectsId, @Param("type") Integer type, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate, @Param("lessonType") String lessonType, @Param("gradeId") String gradeId, @Param("detailType") Integer detailType, @Param("yearClassId") String yearClassId, @Param("classTypeIdStr") String classTypeIdStr, @Param("endDateTimeBefore") String endDateTimeBefore, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    /**
     * 请假补课率战队
     */
    @Select({"<script>",
            "SELECT",
            "team_id,team_name,team_pid,t01.sourse_id AS teacher_id,",
            "getStaffNameForId(t01.teacher_id) AS teacher_name,",
            "IFNULL( SUM( ShouldCount ), 0 ) AS ShouldCount,",
            "IFNULL( SUM( AlreadyCount ), 0 ) AS AlreadyCount,",
            "IFNULL( SUM( NotCount ), 0 ) AS NotCount,",
            "IFNULL( SUM( NotAlreadyBuckleCount ), 0 ) AS NotAlreadyBuckleCount,",
            "IFNULL( SUM( NotAlreadyNotBuckleCount ), 0 ) AS NotAlreadyNotBuckleCount,",
            "IFNULL( SUM( NowAlreadyCount ), 0 ) AS NowAlreadyCount ",
            "FROM (",
            "SELECT ",
            "td.*,",
            "td.sourse_id AS teacher_id,",
            "tm.team_name,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM ",
            "track_market AS tm ",
            "LEFT JOIN track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType}",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "GROUP BY tm.id,td.sourse_id ",
            ") AS t01",
            "LEFT JOIN ( ",
            "SELECT t01.school_id,t01.teacher_id,t01.teacher_name,t01.school_name,t02.year_class_id,t02.course_type_id,",

            "COUNT( CASE WHEN t01.STATUS = 2 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS ShouldCount,",

            "COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time &lt;= #{endDate} ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS AlreadyCount,",

            "COUNT( CASE WHEN t01.STATUS = 2  ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) - COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time &lt;= #{endDate} ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS NotCount,",

            "COUNT( CASE WHEN t01.STATUS = 2 AND is_repair &lt;&gt; 1 AND is_deduct_house = 1 AND is_deduct_money = 1 AND buckle_class_house &gt; 0 ",// 未补已扣
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS NotAlreadyBuckleCount, ",

            "COUNT( CASE WHEN t01.STATUS = 2 AND is_repair &lt;&gt; 1 AND buckle_class_money = 0 ",// 未补未扣
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS NotAlreadyNotBuckleCount,",

            "COUNT( CASE WHEN t01.STATUS = 2 AND t01.is_repair = 1 AND t01.repair_end_date_time BETWEEN #{startDate} AND #{endDate} ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "t02.year_class_id in (${yearClassId}) ",
            "and t01.subjects_id IN (${subjectsId})  ",
            "and t01.school_id in(${schoolId}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t01.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
            "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
            "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            "THEN 1 END ) AS NowAlreadyCount",

            "FROM",
            "record_course AS t01 ",
            "LEFT JOIN grade AS t02 ON t01.old_grade_id = t02.id ",
            "LEFT JOIN repair_course AS t03 ON t01.repair_id = t03.id ",
            "WHERE ",
            "t01.is_deduct_house &lt;&gt; 3  ",
            "AND t01.deduct_type &lt;&gt; 4 ",
            "AND t01.year_part = ${yearPart} ",
            "AND t01.QUARTER = ${quarterNum} ",
            "AND t01.created_at &lt;= #{endDate} ",
            "AND t01.STATUS = 2 ",
            "AND ((t01.deleted = 0 ) OR ( t01.deleted = 1 AND t01.deleted_at &gt;= #{endDateTimeBefore})) ",
            "AND t01.`lesson_type` = 1 ",
            "GROUP BY teacher_id ",
            ") AS t02 ON t02.teacher_id = t01.teacher_id ",
            "AND ( find_in_set( t02.year_class_id, t01.year_class_id_str ) OR t01.year_class_id_str = '' ) ",
            "AND ( find_in_set( t02.school_id, t01.school_id_str ) OR t01.school_id_str = '' ) ",
            "WHERE 1=1 ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
                "AND team_id in (${teamId})",
            "</when>",
            "GROUP BY team_id",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            ",teacher_id",
            "</when>",
            "</script>"})
    public abstract List<CancellationRate> cancellationRateTeamList(@Param("schoolId") String schoolId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("subjectsId") String subjectsId, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate, @Param("yearClassId") String yearClassId, @Param("classTypeIdStr") String classTypeIdStr, @Param("endDateTimeBefore") String endDateTimeBefore, @Param("teamId") String teamId, @Param("classify") String classify, @Param("trackType") String trackType, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    /**
     * 请假补课率战队详情
     */
    @Select({"<script>",
            "SELECT t02.* ",
            "FROM (",
            "SELECT ",
            "td.*,",
            "td.sourse_id AS teacher_id,",
            "tm.team_name,",
            "tm.id AS team_id,",
            "tm.pid AS team_pid ",
            "FROM ",
            "track_market AS tm ",
            "LEFT JOIN track_detail AS td ON tm.id = td.track_id AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType}",
            "AND tm.id in (${teamId})",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "AND td.sourse_id = ${teacherId}",
            "GROUP BY tm.id,td.sourse_id ",
            ") AS t01",
            "INNER JOIN ( ",
            "SELECT t01.student_name,t01.teacher_name,t02.`name` AS grade_name,t02.course_type_id,t01.repair_end_date_time,t03.time_start,t03.time_end,t02.teacher_id ,t02.school_id,t01.lesson_num,t01.year_class_id,getDictName(t01.year_class_id, 14)  as year_class_name",
            "FROM",
            "record_course AS t01",
            "LEFT JOIN grade AS t02 ON t01.old_grade_id = t02.id ",
            "LEFT JOIN repair_course AS t03 ON t01.repair_id = t03.id ",
            "WHERE",
            "t01.is_deduct_house &lt;&gt; 3  ",
            "AND t01.deduct_type &lt;&gt; 4 ",
            "AND t01.year_part = ${yearPart} ",
            "AND t01.QUARTER = ${quarterNum} ",
            "AND t01.created_at &lt;= #{endDate} ",
            "AND t01.STATUS = 2 ",
            "AND t01.`lesson_type` = 1 ",
            "AND t01.`teacher_id` = ${teacherId} ",
            "AND ((t01.deleted = 0 ) OR ( t01.deleted = 1 AND t01.deleted_at &gt;= #{endDateTimeBefore})) ",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
                "and t01.old_grade_id = ${gradeId}",
            "</when>",
            "<if test= 'detailType == 1'>",
                "AND t01.is_repair = 1 ",
                "AND t01.repair_end_date_time &lt;= #{endDate} ",
            "</if>",
            "<if test= 'detailType == 2'>",
                "AND t01.is_repair IN (0,2)",
            "</if>",
            "<if test= 'detailType == 3'>",
                "AND t01.is_repair = 1 ",
                "AND t01.repair_end_date_time BETWEEN #{startDate} AND #{endDate} ",
            "</if>",
            "<if test= 'detailType == 4'>",// 未补已扣
                "AND is_repair &lt;&gt; 1 AND is_deduct_house = 1 AND is_deduct_money = 1 AND buckle_class_house > 0 ",
            "</if>",
            "<if test= 'detailType == 5'>",// 未补未扣
                "AND is_repair &lt;&gt; 1 AND buckle_class_money = 0 ",
            "</if>",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "t02.year_class_id in(${authAdminContent.yearClassIds})",
            "and t01.subjects_id in(${authAdminContent.subjectsIds})",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t01.subjects_id IN (${subjectsId})",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t01.teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND t01.school_id IN (${schoolId}) ",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and t02.year_class_id in (${yearClassId})",
            "</when>",
            ") OR (",
            " t01.teacher_id = ${leadDataRs.teacherId} AND t01.school_id IN ( ${leadDataRs.schoolIds} ) AND t02.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t01.subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
            // ---权限数据结束---
            "<when test='classTypeIdStr!=null and classTypeIdStr!=&apos;&apos; '>",
                "and t02.course_type_id in (${classTypeIdStr})",
            "</when>",
            "<when test='startLessonNum!=null and startLessonNum!=&apos;&apos; and endLessonNum!=null and endLessonNum!=&apos;&apos;'>",
                "AND t01.lesson_num BETWEEN ${startLessonNum} AND ${endLessonNum} ",
            "</when>",
            ") AS t02 ON t02.teacher_id = t01.teacher_id ",
            "AND ( find_in_set( t02.year_class_id, t01.year_class_id_str ) OR t01.year_class_id_str = '' ) ",
            "AND (find_in_set( t02.school_id, t01.school_id_str ) OR t01.school_id_str = '' )",
            "</script>"})
    public abstract IPage<CancellationRate> cancellationRateTeamDetail(IPage<?> iPage, @Param("schoolId") String schoolId, @Param("teacherId") Long teacherId, @Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("subjectsId") String subjectsId, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate, @Param("gradeId") String gradeId, @Param("detailType") Integer detailType, @Param("yearClassId") String yearClassId, @Param("classTypeIdStr") String classTypeIdStr, @Param("endDateTimeBefore") String endDateTimeBefore, @Param("teamId") String teamId, @Param("classify") String classify, @Param("trackType") String trackType, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);


    @Select("SELECT admin_id FROM role_admin WHERE role_id = 1568160887369994242")
    public abstract List<Long> selectAdminId();

    @Select("SELECT admin_id FROM role_admin WHERE role_id = 1568160769463914497")
    public abstract List<Long> selectAdminCId();

    @Select("SELECT admin_id FROM role_admin WHERE role_id = 1568160915052400642")
    public abstract List<Long> selectAdminZId();

    @Select("select name from student where id = #{student_id}")
    public abstract String getStudentName(@Param("student_id") String studentId);

    @Select("select * FROM student_grade ${ew.customSqlSegment}")
    public abstract List<ResidueStudent> semesterDetailAll(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    /**
     * 获取请假课次
     *
     * @param wrapper
     * @return
     */
    @Select("select IFNULL(SUM(buckle_class_house),0) as buckle_class_house from record_course ${ew.customSqlSegment} ")
    public abstract Integer getLeaveCourseCount(@Param(Constants.WRAPPER) Wrapper wrapper);

    @Select("SELECT SUM(buckle_class_house)/3  FROM record_course ${ew.customSqlSegment}")
    public abstract Integer sumBuckleClassHouse(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);

    /**
     * 精品课 到课率、迟到率、旷课率，列表
     */
    @Select({"<script>",
            "SELECT *,",
            "( no_arrived_count_child+truancy_count ) AS no_arrived_count,",// 到课率：未到 = 未签到 + 旷课
            "( late_count + no_arrived_count_child + truancy_count ) AS tardiness_rate_count",// 准时率：未到 = 未签到 + 超时签到 + 旷课
            "FROM(",
            "SELECT",
            "school_id,",
            "getSchoolName ( school_id ) AS school_name,",
            "teacher_id,",
            "teacher_name,",
            "grade_id,",
            "subjects_id, ",
            "year_class_id,",
            "<if test= 'type == 6'>",
            "school_pid,",
            "sum( CASE WHEN teacher_id is not null ",
                // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "year_class_id in (${yearClassIdStr}) ",
            "and subjects_id IN (${subjectsId})  ",
            "and school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
                "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
                    "and time_start &gt;=#{timeStart} and time_end &lt;=#{timeEnd} ",
                "</when>",
                "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
                    "and time_start &lt;=#{timeEnd} ",
                "</when>",
            "THEN 1 ELSE 0 END ) AS student_all_count,",

            "sum( CASE WHEN `status` = 1 ",
                // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "year_class_id in (${yearClassIdStr}) ",
            "and subjects_id IN (${subjectsId})  ",
            "and school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
                "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
                    "and time_start &gt;=#{timeStart} and time_end &lt;=#{timeEnd} ",
                "</when>",
                "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
                    "and time_start &lt;=#{timeEnd} ",
                "</when>",
            "THEN 1 ELSE 0 END ) AS arrived_count,",

            "sum( CASE WHEN (( `status` = 2 ) OR ( `status` IS NULL AND leave_apply_id IS NOT NULL )) ",
                // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "year_class_id in (${yearClassIdStr}) ",
            "and subjects_id IN (${subjectsId})  ",
            "and school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
                "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
                    "and time_start &gt;=#{timeStart} and time_end &lt;=#{timeEnd} ",
                "</when>",
                "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
                    "and time_start &lt;=#{timeEnd} ",
                "</when>",
            "THEN 1 ELSE 0 END ) AS leave_count,",

            "sum( CASE WHEN (`reach_type` = 2 ) ",
                // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "year_class_id in (${yearClassIdStr}) ",
            "and subjects_id IN (${subjectsId})  ",
            "and school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
                "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
                    "and time_start &gt;=#{timeStart} and time_end &lt;=#{timeEnd} ",
                "</when>",
                "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
                    "and time_start &lt;=#{timeEnd} ",
                "</when>",
            "THEN 1 ELSE 0 END ) AS late_count,",

            "sum( CASE WHEN teacher_id IS NOT NULL AND STATUS IS NULL AND leave_apply_id IS NULL ",
                // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "year_class_id in (${yearClassIdStr}) ",
            "and subjects_id IN (${subjectsId})  ",
            "and school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
                "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
                    "and time_start &gt;=#{timeStart} and time_end &lt;=#{timeEnd} ",
                "</when>",
                "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
                    "and time_start &lt;=#{timeEnd} ",
                "</when>",
            "THEN 1 ELSE 0 END ) AS no_arrived_count_child, ",

            "sum( CASE WHEN t.`status` = 3 ",
                // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
                "and ((",
                "year_class_id in (${yearClassIdStr}) ",
                "and subjects_id IN (${subjectsId})  ",
                "and school_id in(${schoolIdStr}) ",
                "<when test='authAdminContent.isPerson==1'>",
                "and teacher_id = ${authAdminContent.teacherId} ",
                "</when>",
                ") or (teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
                "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
                    "and time_start &gt;=#{timeStart} and time_end &lt;=#{timeEnd} ",
                "</when>",
                "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
                    "and time_start &lt;=#{timeEnd} ",
                "</when>",
            "THEN 1 ELSE 0 END ) AS truancy_count ",

            "</if>",

            "<if test= 'type != 6'>",
            "sum( CASE WHEN teacher_id is not null THEN 1 ELSE 0 END ) AS student_all_count,",
            "sum( CASE WHEN `status` = 1 THEN 1 ELSE 0 END ) AS arrived_count,",
            "sum( CASE WHEN (( `status` = 2 ) OR ( `status` IS NULL AND leave_apply_id IS NOT NULL )) THEN 1 ELSE 0 END ) AS leave_count,",
            "sum( CASE WHEN `reach_type` = 2 THEN 1 ELSE 0 END ) AS late_count,",
            "sum( CASE WHEN teacher_id IS NOT NULL AND STATUS IS NULL AND leave_apply_id IS NULL THEN 1 ELSE 0 END ) AS no_arrived_count_child,",
            "sum( CASE WHEN t.`status` = 3 THEN 1 ELSE 0 END ) AS truancy_count ",
            "</if>",

            "FROM",
            "(",
            "<if test= 'type == 6'>",
                "SELECT ",
                "t01.school_name,",
                "t01.pid AS school_pid,",
                "t01.school_id,",
                "teacher_id,",
                "student_id,",
                "`status`,",
                "reach_type,",
                "grade_id,",
                "subjects_id,",
                "year_class_id,",
                "leave_apply_id,",
                "time_start,",
                "time_end,",
                "teacher_name ",
                "FROM ",
                "( SELECT * FROM school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0 ) AS t01",
            "LEFT JOIN (",
            "</if>",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "sff0.`name` AS teacher_name,",
            "t6.id AS leave_apply_id ",
            "FROM",
            "record_course AS t1 ",
            "INNER JOIN (select id,`name` from staff) AS sff0 ON sff0.id = t1.old_teacher_id",
            "LEFT JOIN student_leave_apply AS t6 ON t1.scheduling_detail_id = t6.scheduling_detail_id AND t6.STATUS &lt;&gt; 2 AND t1.student_id = t6.student_id ",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = ${lessonType} ",
            "AND t1.`course_type` &lt;&gt; 8 ",
            "and t1.old_teacher_id is not null",
            "AND t1.end_date_time &lt; NOW() ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "and t1.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
                "AND t1.course_type &lt;&gt; 3",
            "</when>",
            "<when test='(startLessonNum==null or startLessonNum==&apos;&apos;) and (endLessonNum==null or endLessonNum==&apos;&apos;)'>",
                "<when test='startDate!=null and startDate!=&apos;&apos; '>",
                    "and t1.school_date &gt;=#{startDate} ",
                "</when>",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
                "and t1.school_date &lt;=#{endDate} ",
            "</when>",
            "<when test='name!=null and name!=&apos;&apos; '>",
                "and sff0.`name` LIKE '%${name}%'",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                "and sff0.`id` = ${teacherId}",
            "</when>",

            "UNION ALL",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t1.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "sff1.`name` AS teacher_name,",
            "t6.id AS leave_apply_id ",
            "FROM",
            "${courseSchedulingDetailName} AS t2",
            "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "AND t1.reading_status in(${readingStatus}) ",
            "AND t1.`status` = 1",
            "and t2.end_date_time  &gt;= t1.created_at",
            "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0 ",
            "AND t3.student_id = t1.student_id",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t3.course_type &lt;&gt; 3",
            "</when>",
            "LEFT JOIN grade AS t4 ON t1.grade_id = t4.id",
            "INNER JOIN staff AS sff1 ON sff1.id = t4.teacher_id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id",
            "AND t5.deleted = 0 ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t5.course_type &lt;&gt; 3",
            "</when>",
            "LEFT JOIN student_leave_apply AS t6 ON t2.id = t6.scheduling_detail_id AND t6.STATUS &lt;&gt; 2 AND t1.student_id = t6.student_id ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.end_date_time &gt;= NOW() ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t2.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
            "and t2.school_date &gt;=#{startDate} ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
            "and t2.school_date &lt;=#{endDate} ",
            "</when>",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff1.`name` LIKE '%${name}%'",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "and sff1.`id` = ${teacherId}",
            "</when>",
            "GROUP BY t1.school_id,t1.subjects_id,t1.student_id,t1.lesson_type",

            "UNION ALL",

            "SELECT",
            "t2.school_id,",
            "t2.old_teacher_id AS teacher_id,",
            "t2.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t2.old_grade_id AS grade_id,",
            "t2.subjects_id,",
            "t2.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "sff.`name` AS teacher_name,",
            "NULL AS leave_apply_id ",
            "FROM",
            "repair_course AS t2",
            "INNER JOIN staff AS sff ON sff.id = t2.old_teacher_id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t2.student_id ",
            "AND t5.deleted = 0 ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t2.course_type &lt;&gt; 3",
                "AND t5.course_type &lt;&gt; 3",
            "</when>",
            "WHERE",
            "t2.deleted = 0 ",
            "AND t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.end_date_time &gt;= NOW() ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "and t2.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
                "and t2.school_date &gt;=#{startDate} ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
                "and t2.school_date &lt;=#{endDate} ",
            "</when>",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.lesson_type = ${lessonType} ",
            "and t2.old_teacher_id is not null ",
            "<when test='name!=null and name!=&apos;&apos; '>",
                "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "<if test= 'type == 6'>",
            ") AS t02 ON t01.school_id = t02.school_id ",
            "</if>",
            ") AS t where 1=1",
            "<if test= 'type != 6'>",

            "<if test= 'type == 3'>",
            "and teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242) ",
            "</if>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==1'>",
            "and teacher_id in(select sourse_id from track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='trackId!=null and trackId!=&apos;&apos; and type ==4'>",
            "and school_id in(select sourse_id from track_detail where deleted = 0 and track_id =#{trackId}) ",
            "</when>",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and time_start &gt;=#{timeStart} and time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and time_start &lt;=#{timeEnd} ",
            "</when>",

            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "year_class_id in (${yearClassIdStr}) ",
            "and subjects_id IN (${subjectsId})  ",
            "and school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
                "and teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---

            "</if>",
            "GROUP BY",
            "<if test= 'type == 1 or type == 3'>",
            "teacher_id",
            "</if>",
            "<if test= 'type == 2'>",
            "school_id,teacher_id",
            "</if>",
            "<if test= 'type == 4 or type == 6'>",
            "school_id",
            "</if>",
            "<if test= 'isYearClass == 1'>",
            ",year_class_id",
            "</if>",
            ") AS tt2",
            "</script>"})
    public abstract List<ArrivalRate> arrivalRate(@Param("schoolIdStr") String schoolIdStr, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("type") String type, @Param("subjectsId") String subjectsId, @Param("startDateLast") String startDateLast, @Param("endDateLast") String endDateLast, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("timeStart") String timeStart, @Param("timeEnd") String timeEnd, @Param("lessonType") Integer lessonType, @Param("rateType") Integer rateType, @Param("schoolId") String schoolId, @Param("yearClassIdStr") String yearClassIdStr, @Param("trackId") String trackId, @Param("name") String name, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("teacherId") String teacherId, @Param("readingStatus") String readingStatus, @Param("courseSchedulingDetailName") String courseSchedulingDetailName, @Param("isYearClass") String isYearClass, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    /**
     * 精品课 到课率、迟到率、旷课率，详情
     */
    @Select({"<script>",
            "SELECT",
            "t.school_id,",
            "t.grade_id,",
            "t.teacher_id,",
            "t.subjects_id,",
            "t.student_id,",
            "t.school_date,",
            "t.time_start,",
            "t.time_end,",
            "t.leave_apply_id,",
            "t8.linkman_phone,",
            "getSchoolName ( t.school_id ) AS school_name,",
            "getStaffNameForId ( t.teacher_id ) AS teacher_name,",
            "t7.`name` AS grade_name,",
            "t8.name as student_name,",
            "IFNULL( t.`status`, 4 ) AS `status`,",
            "(",
            "IFNULL( t6.in_date_time, t6.out_date_time )) AS in_date_time,",
            "lesson_num ",
            "FROM",
            "(",
            "SELECT",
            "t1.scheduling_detail_id,",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.school_date,",
            "t1.time_start,",
            "t1.time_end, ",
            "t6.id AS leave_apply_id, ",
            "t1.lesson_num ",
            "FROM",
            "record_course AS t1 ",
            "LEFT JOIN student_leave_apply AS t6 ON t1.scheduling_detail_id = t6.scheduling_detail_id AND t6.STATUS &lt;&gt; 2 AND t1.student_id = t6.student_id ",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = ${lessonType} ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND t1.end_date_time &lt; NOW() ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t1.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='(startLessonNum==null or startLessonNum==&apos;&apos;) and (endLessonNum==null or endLessonNum==&apos;&apos;)'>",
                "<when test='startDate!=null and startDate!=&apos;&apos; '>",
                    "and t1.school_date &gt;=#{startDate} ",
                "</when>",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
                "and t1.school_date &lt;=#{endDate} ",
            "</when>",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t1.course_type &lt;&gt; 3",
            "</when>",

            "UNION ALL",

            "SELECT",
            "t2.id AS scheduling_detail_id,",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t1.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.school_date,",
            "t2.time_start,",
            "t2.time_end, ",
            "t6.id AS leave_apply_id, ",
            "t2.lesson_num ",
            "FROM",
            "${courseSchedulingDetailName} AS t2",
            "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "AND t1.reading_status in(${readingStatus}) ",
            "AND t1.`status` = 1",
            "and t2.end_date_time &gt;= t1.created_at",
            "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t3.course_type &lt;&gt; 3",
            "</when>",
            "LEFT JOIN grade AS t4 ON t1.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id",
            "AND t5.deleted = 0 ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t5.course_type &lt;&gt; 3",
            "</when>",
            "LEFT JOIN student_leave_apply AS t6 ON t2.id = t6.scheduling_detail_id AND t6.STATUS &lt;&gt; 2 AND t1.student_id = t6.student_id ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t2.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
                "and t2.school_date &gt;=#{startDate} ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
                "and t2.school_date &lt;=#{endDate} ",
            "</when>",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.end_date_time &gt;= NOW() ",
            "AND t3.id IS NULL ",
            "GROUP BY",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",

            "UNION ALL ",

            "SELECT",
            "t2.id AS scheduling_detail_id,",
            "t2.school_id,",
            "t2.old_teacher_id AS teacher_id,",
            "t2.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t2.old_grade_id AS grade_id,",
            "t2.subjects_id,",
            "t2.year_class_id,",
            "t2.school_date,",
            "t2.time_start,",
            "t2.time_end,",
            "NULL AS leave_apply_id, ",
            "t2.lesson_num ",
            "FROM",
            "repair_course AS t2",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t2.student_id ",
            "AND t5.deleted = 0 ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t2.course_type &lt;&gt; 3",
                "AND t5.course_type &lt;&gt; 3",
            "</when>",
            "WHERE",
            "t2.deleted = 0 ",
            "AND t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.end_date_time &gt;= NOW() ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t2.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
            "and t2.school_date &gt;=#{startDate} ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
            "and t2.school_date &lt;=#{endDate} ",
            "</when>",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.old_teacher_id IS NOT NULL ",
            ") AS t",
            "LEFT JOIN student_sign_in AS t6 ON t6.scheduling_detail_id = t.scheduling_detail_id ",
            "AND t6.student_id = t.student_id",
            "LEFT JOIN grade AS t7 ON t7.id = t.grade_id ",
            "LEFT JOIN student AS t8 ON t8.id = t.student_id ",
            "WHERE",
            "1 = 1 ",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "t.subjects_id in(${authAdminContent.subjectsIds})",
            "and t7.year_class_id in(${authAdminContent.yearClassIds})",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                "AND t.teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                "AND t.school_id IN (${schoolId}) ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                "and t.subjects_id IN (${subjectsId}) ",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                "and t7.year_class_id in (${yearClassIdStr})",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND t.school_id IN ( ${leadDataRs.schoolIds} ) AND t7.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---

            "<when test='gradeId!=null and gradeId!=&apos;&apos; '>",
            "AND t.`grade_id` = ${gradeId} ",
            "</when>",
            "<when test='punctualityType==null or punctualityType==&apos;&apos;'>",
                "<when test='status!=null and status!=&apos;&apos; and status == 1'>",// 已到
                    "and t.status=1 ",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 2'>",// 未到
                    "and ((t.teacher_id IS NOT NULL AND t.STATUS IS NULL AND t.leave_apply_id IS NULL) or (t.status = 3 ))",// 未到 = 未签到 + 旷课
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 3'>",// 旷课
                    "and t.status = 3 ",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 4'>",// 请假
                    "and (( t.`status` = 2 ) OR ( t.`status` IS NULL AND leave_apply_id IS NOT NULL ))",
                "</when>",
            "</when>",
            "<when test='punctualityType!=null and punctualityType!=&apos;&apos;'>",
                "<if test= 'punctualityType == 0'>",// 准时率
                    "<when test='status!=null and status!=&apos;&apos; and status==0 '>",
                        "and (`reach_type` = 2 or (t.teacher_id IS NOT NULL AND t.STATUS IS NULL AND t.leave_apply_id IS NULL) or t.status = 3 )",// 迟到
                    "</when>",
                    "<when test='status!=null and status!=&apos;&apos; and status == 1'>",
                        "and (t.status=${status} and reach_type = 2 and t6.id is not null)",
                    "</when>",
                    "<when test='status!=null and status!=&apos;&apos; and status == 2'>",
                        "and ((t.status=2 or t.status is null) or (t.status=1 and reach_type = 2 and t6.id is null))",
                    "</when>",
                    "<when test='status!=null and status!=&apos;&apos; and status == 4'>",// 请假
                        "and (( t.`status` = 2 ) OR ( t.`status` IS NULL AND leave_apply_id IS NOT NULL ))",
                    "</when>",
                "</if>",
                "<if test= 'punctualityType == 1'>",// 准时率 准时
                    "and (t.status=1 AND reach_type = 1)",
                "</if>",
            "</when>",
            "</script>"})
    public abstract IPage<RecordCourse> arrivalRateDetail(IPage<?> page, @Param("schoolId") String schoolId, @Param("subjectsId") String subjectsId, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("startDateLast") String startDateLast, @Param("endDateLast") String endDateLast, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("gradeId") String gradeId, @Param("teacherId") String teacherId, @Param("type") String type, @Param("status") String status, @Param("timeStart") String timeStart, @Param("timeEnd") String timeEnd, @Param("lessonType") Integer lessonType, @Param("rateType") Integer rateType, @Param("yearClassIdStr") String yearClassIdStr, @Param("punctualityType") String punctualityType, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("readingStatus") String readingStatus, @Param("courseSchedulingDetailName") String courseSchedulingDetailName, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    /**
     * 【精品课】 到课率、迟到率、旷课率，战队列表
     */
    @Select({"<script>",
            "SELECT ",
            "team_id,teacher_id,teacherName,team_name,team_pid,year_class_id,",
            "SUM( student_all ) AS student_all_count,",// 总数
            "SUM( arrived ) AS arrived_count,",// 已到
            "SUM( `leave` ) AS leave_count,",// 请假
            "SUM( truancy_count ) AS truancy_count,",// 旷课
            "SUM( no_arrived_count_child + truancy_count) AS no_arrived_count,",// 未到 = 未签到 + 旷课
            "SUM( late_count + no_arrived_count_child + truancy_count )  AS tardiness_rate_count ",// 未到 = 未签到 + 超时签到 + 旷课
            "FROM( ",
            "SELECT",

            "sum( CASE WHEN t.student_id IS NOT NULL ",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "THEN 1 ELSE 0 END ) AS student_all,",

            "sum( CASE WHEN t.`status` = 1 ",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "THEN 1 ELSE 0 END ) AS arrived,",

            "sum( CASE WHEN (( `status` = 2 ) OR ( t.`status` = 0 AND leave_apply_id IS NOT NULL )) ",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "THEN 1 ELSE 0 END ) AS `leave`,",

            "sum( CASE WHEN (t.`reach_type` = 2 ) ",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "THEN 1 ELSE 0 END ) AS late_count,",

            "sum( CASE WHEN t1.teacher_id IS NOT NULL AND t.`status` = 0 AND leave_apply_id IS NULL ",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "THEN 1 ELSE 0 END ) AS no_arrived_count_child,",

            "sum( CASE WHEN ( t.`status` = 3) ",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "THEN 1 ELSE 0 END ) AS truancy_count, ",

            "school_id,",
            "getSchoolName ( school_id ) AS school_name,",
            "t1.teacher_id as teacher_id,",
            "sff.`name` AS teacherName,",
            "grade_id,",
            "subjects_id,",
            "year_class_id,",
            "team_id,t1.team_name,t1.team_pid ",
            "FROM",
            "( ",
            "SELECT ",
            "td.*,td.sourse_id as teacher_id ,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
            "FROM ",
            "track_market AS tm ",
            "LEFT JOIN track_detail AS td ON tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            "and tm.id IN (${teamId}) ",
            "</when>",
            "GROUP BY ",
            "tm.id,td.sourse_id ",
            ") AS t1 ",
            "LEFT JOIN (select id,`name` from staff) AS sff ON sff.id = t1.teacher_id",
            "LEFT JOIN (",
            "SELECT school_id,teacher_id,student_id,time_start,time_end,",
            "reach_type,grade_id,subjects_id,year_class_id,leave_apply_id,",
            "IFNULL(`status`,0) as `status`",
            "FROM (",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t6.id AS leave_apply_id ",
            "FROM",
            "record_course AS t1 ",
            "LEFT JOIN student_leave_apply AS t6 ON t1.scheduling_detail_id = t6.scheduling_detail_id AND t6.STATUS &lt;&gt; 2 AND t1.student_id = t6.student_id ",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = ${lessonType} ",
            "AND t1.`course_type` &lt;&gt; 8 ",
            "and t1.old_teacher_id is not null",
            "AND t1.end_date_time &lt; NOW()",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "and t1.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
                "AND t1.course_type &lt;&gt; 3",
            "</when>",
            "<when test='(startLessonNum==null or startLessonNum==&apos;&apos;) and (endLessonNum==null or endLessonNum==&apos;&apos;)'>",
                "<when test='startDate!=null and startDate!=&apos;&apos; '>",
                    "and t1.school_date &gt;=#{startDate} ",
                "</when>",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
                "and t1.school_date &lt;=#{endDate} ",
            "</when>",

            "UNION ALL",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t1.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "t6.id AS leave_apply_id ",
            "FROM",
            "${courseSchedulingDetailName} AS t2",
            "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "AND t1.reading_status in(${readingStatus}) ",
            "AND t1.`status` = 1",
            "and t2.end_date_time  &gt;= t1.created_at",
            "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0 ",
            "AND t3.student_id = t1.student_id",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t3.course_type &lt;&gt; 3",
            "</when>",
            "LEFT JOIN grade AS t4 ON t1.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id",
            "AND t5.deleted = 0 ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t5.course_type &lt;&gt; 3",
            "</when>",
            "LEFT JOIN student_leave_apply AS t6 ON t2.id = t6.scheduling_detail_id AND t6.STATUS &lt;&gt; 2 AND t1.student_id = t6.student_id ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.end_date_time &gt;= NOW()",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "and t2.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
                "and t2.school_date &gt;=#{startDate} ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
                "and t2.school_date &lt;=#{endDate} ",
            "</when>",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL",
            "GROUP BY t1.school_id,t1.subjects_id,t1.student_id,t1.lesson_type",
            "UNION ALL",
            "SELECT",
            "t2.school_id,",
            "t2.old_teacher_id AS teacher_id,",
            "t2.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t2.old_grade_id AS grade_id,",
            "t2.subjects_id,",
            "t2.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "NULL AS leave_apply_id ",
            "FROM",
            "repair_course AS t2",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t2.student_id ",
            "AND t5.deleted = 0 ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t2.course_type &lt;&gt; 3",
                "AND t5.course_type &lt;&gt; 3",
            "</when>",
            "WHERE",
            "t2.deleted = 0 ",
            "AND t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.end_date_time &gt;= NOW()",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t2.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
            "and t2.school_date &gt;=#{startDate} ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
            "and t2.school_date &lt;=#{endDate} ",
            "</when>",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.lesson_type = ${lessonType} ",
            "and t2.old_teacher_id is not null ",
            ")AS ttt",
            "where 1=1 ",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and ttt.time_start &gt;=#{timeStart} and ttt.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and ttt.time_start &lt;=#{timeEnd} ",
            "</when>",

            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "ttt.year_class_id in (${yearClassIdStr}) ",
            "and ttt.subjects_id IN (${subjectsId})  ",
            "and ttt.school_id in(${schoolIdStr}) ",
            ") or (ttt.teacher_id = ${leadDataRs.teacherId} AND ttt.school_id IN ( ${leadDataRs.schoolIds} ) AND ttt.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND ttt.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---

            ") AS t ON t.teacher_id = t1.teacher_id  ",
            "AND ( find_in_set( t.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "AND ( find_in_set( t.grade_id, t1.grade_id_str ) OR t1.grade_id_str = '' ) ",
            "where 1=1 ",
            "GROUP BY t.teacher_id,t1.team_id ",
            "<if test= 'isYearClass == 1'>",
                ",year_class_id",
            "</if>",
            ") AS tt2 ",
            "GROUP BY team_id ",
            "<when test='isTeamDetails!=null and isTeamDetails!=&apos;&apos; and isTeamDetails == 1'>",
                ",teacher_id",
            "</when>",
            "<if test= 'isYearClass == 1'>",
                ",year_class_id",
            "</if>",
            "</script>"})
    public abstract List<ArrivalRate> arrivalRateTeam(@Param("schoolIdStr") String schoolIdStr, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("subjectsId") String subjectsId, @Param("startDateLast") String startDateLast, @Param("endDateLast") String endDateLast, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("timeStart") String timeStart, @Param("timeEnd") String timeEnd, @Param("lessonType") Integer lessonType, @Param("yearClassIdStr") String yearClassIdStr, @Param("isTeamDetails") String isTeamDetails, @Param("classify") String classify, @Param("trackType") String trackType, @Param("teamId") String teamId, @Param("name") String name, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("readingStatus") String readingStatus, @Param("courseSchedulingDetailName") String courseSchedulingDetailName, @Param("isYearClass") String isYearClass, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    /**
     * 精品课 到课率、迟到率、旷课率，战队详情
     */
    @Select({"<script>",
            "SELECT",
            "t.school_id,t.grade_id,t.teacher_id,t.subjects_id,t.student_id,t.school_date,t.time_start,t.time_end, ",
            "getSchoolName ( t.school_id ) AS school_name,",
            "getStaffNameForId ( t.teacher_id ) AS teacher_name,",
            "t7.`name` AS grade_name,",
            "t8.`name` AS student_name,t8.linkman_phone,",
            "t.leave_apply_id,",
            "IFNULL( t.`status`, 4 ) AS `status`,",
            "IFNULL( t6.in_date_time, t6.out_date_time ) AS in_date_time, ",
            "lesson_num ",
            "FROM",
            "( ",
            "SELECT ",
            "td.*,td.sourse_id as teacher_id,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
            "FROM ",
            "track_market AS tm ",
            "LEFT JOIN track_detail AS td ON tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "AND tm.id = ${teamId} ",
            "AND td.sourse_id = ${teacherId} ",
            "GROUP BY ",
            "tm.id,td.sourse_id ",
            ") AS t1 ",
            "LEFT JOIN (",
            "SELECT school_id,teacher_id,student_id,time_start,time_end,leave_apply_id,",
            "reach_type,grade_id,subjects_id,year_class_id,",
            "`status`,",
            "school_date,scheduling_detail_id,",
            "lesson_num ",
            "FROM (",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.school_date,",
            "t1.scheduling_detail_id,",
            "t6.id AS leave_apply_id, " ,
            "t1.lesson_num ",
            "FROM",
            "record_course AS t1 ",
            "LEFT JOIN student_leave_apply AS t6 ON t1.scheduling_detail_id = t6.scheduling_detail_id AND t6.STATUS &lt;&gt; 2 AND t1.student_id = t6.student_id ",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = ${lessonType} ",
            "and t1.old_teacher_id is not null",
            "AND t1.end_date_time &lt; NOW() ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t1.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "AND t1.course_type &lt;&gt; 3",
            "</when>",
            "<when test='(startLessonNum==null or startLessonNum==&apos;&apos;) and (endLessonNum==null or endLessonNum==&apos;&apos;)'>",
                "<when test='startDate!=null and startDate!=&apos;&apos; '>",
                    "and t1.school_date &gt;=#{startDate} ",
                "</when>",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
            "and t1.school_date &lt;=#{endDate} ",
            "</when>",
            "UNION ALL",
            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t1.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "t2.school_date,",
            "t5.scheduling_detail_id,",
            "t6.id AS leave_apply_id," ,
            "t2.lesson_num ",
            "FROM",
            "${courseSchedulingDetailName} AS t2",
            "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "AND t1.reading_status in(${readingStatus}) ",
            "AND t1.`status` = 1",
            "and t2.end_date_time  &gt;= t1.created_at",
            "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "AND t3.course_type &lt;&gt; 3",
            "</when>",
            "LEFT JOIN grade AS t4 ON t1.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id",
            "AND t5.deleted = 0 ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "AND t5.course_type &lt;&gt; 3",
            "</when>",
            "LEFT JOIN student_leave_apply AS t6 ON t2.id = t6.scheduling_detail_id AND t6.STATUS &lt;&gt; 2 AND t1.student_id = t6.student_id ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.end_date_time &gt;= NOW() ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t2.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
            "and t2.school_date &gt;=#{startDate} ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
            "and t2.school_date &lt;=#{endDate} ",
            "</when>",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL",
            "GROUP BY t1.school_id,t1.subjects_id,t1.student_id,t1.lesson_type",
            "UNION ALL",
            "SELECT",
            "t2.school_id,",
            "t2.old_teacher_id AS teacher_id,",
            "t2.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t2.old_grade_id AS grade_id,",
            "t2.subjects_id,",
            "t2.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "t2.school_date,",
            "t5.scheduling_detail_id,",
            "NULL AS leave_apply_id, ",
            "t2.lesson_num ",
            "FROM",
            "repair_course AS t2",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t2.student_id ",
            "AND t5.deleted = 0 ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t2.course_type &lt;&gt; 3",
                "AND t5.course_type &lt;&gt; 3",
            "</when>",
            "WHERE",
            "t2.deleted = 0 ",
            "AND t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.end_date_time &gt;= NOW() ",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "and t2.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
                "and t2.school_date &gt;=#{startDate} ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
                "and t2.school_date &lt;=#{endDate} ",
            "</when>",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.lesson_type = ${lessonType} ",
            "and t2.old_teacher_id is not null ",
            ")AS ttt",
            "where 1=1 ",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and ttt.time_start &gt;=#{timeStart} and ttt.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and ttt.time_start &lt;=#{timeEnd} ",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos; '>",
            "AND ttt.`grade_id` = ${gradeId} ",
            "</when>",
            ") AS t ON t.teacher_id = t1.teacher_id  ",
            "AND ( find_in_set( t.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "AND ( find_in_set( t.grade_id, t1.grade_id_str ) OR t1.grade_id_str = '' )",
            "LEFT JOIN student_sign_in AS t6 ON t6.scheduling_detail_id = t.scheduling_detail_id AND t6.student_id = t.student_id ",
            "LEFT JOIN grade AS t7 ON t7.id = t.grade_id ",
            "LEFT JOIN student AS t8 ON t8.id = t.student_id ",
            "WHERE",
            "t.teacher_id = ${teacherId} ",
            "AND t1.team_id = ${teamId} ",
            
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "t.subjects_id in(${authAdminContent.subjectsIds})",
            "and t7.year_class_id in(${authAdminContent.yearClassIds})",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                "AND t.teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                "AND t.school_id IN (${schoolId}) ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                "and t.subjects_id in (${subjectsId})",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                "and t7.year_class_id in (${yearClassIdStr})",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND t.school_id IN ( ${leadDataRs.schoolIds} ) AND t7.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            
            "<when test='punctualityType==null or punctualityType==&apos;&apos;'>",
                "<when test='status!=null and status!=&apos;&apos; and status == 1'>",// 已到
                    "and t.status=1 ",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 2'>",// 未到
                    "and ((t.teacher_id IS NOT NULL AND t.STATUS IS NULL AND t.leave_apply_id IS NULL) or (t.status = 3 ))",// 未到 = 未签到 + 旷课
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 3'>",// 旷课
                    "and t.status = 3 ",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 4'>",// 请假
                    "and (( t.`status` = 2 ) OR ( t.`status` IS NULL AND leave_apply_id IS NOT NULL ))",
                "</when>",
            "</when>",
            "<when test='punctualityType!=null and punctualityType!=&apos;&apos;'>",
                "<if test= 'punctualityType == 0'>",// 准时率
                "<when test='status==null or status==&apos;&apos; or status==0 '>",
                    "and (`reach_type` = 2 or (t.teacher_id IS NOT NULL AND t.STATUS IS NULL AND t.leave_apply_id IS NULL) or t.status = 3 )",// 迟到
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 1'>",
                    "and (t.status=${status} and reach_type = 2 and t6.id is not null)",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 2'>",
                    "and ((t.status=2 or t.status is null) or (t.status=1 and reach_type = 2 and t6.id is null))",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 4'>",// 请假
                    "and (( t.`status` = 2 ) OR ( t.`status` IS NULL AND leave_apply_id IS NOT NULL ))",
                "</when>",
            "</if>",
            "<if test= 'punctualityType == 1'>",// 准时率 准时
                "and (t.status=1 AND reach_type = 1)",
            "</if>",
            "</when>",
            "</script>"})
    public abstract IPage<RecordCourse> arrivalRateTeamDetail(IPage<?> page, @Param("schoolId") String schoolId, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("subjectsId") String subjectsId, @Param("startDateLast") String startDateLast, @Param("endDateLast") String endDateLast, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("timeStart") String timeStart, @Param("timeEnd") String timeEnd, @Param("lessonType") Integer lessonType, @Param("yearClassIdStr") String yearClassIdStr, @Param("classify") String classify, @Param("trackType") String trackType, @Param("teamId") String teamId, @Param("teacherId") String teacherId, @Param("status") String status, @Param("punctualityType") String punctualityType, @Param("gradeId") String gradeId, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("readingStatus") String readingStatus, @Param("courseSchedulingDetailName") String courseSchedulingDetailName, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    @Update({"call storeAgainBrushData( ${yearPart} , ${quarterNum} , ${subjectsId} , '${yearClassIdStr}' , null ); "})
    public void storeAgainBrushData(@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("subjectsId") Long subjectsId, @Param("yearClassIdStr") String yearClassIdStr, @Param("classTypeIdStr") String classTypeIdStr);

    /**
     * 刷题班、智能课 到课率、旷课率列表
     */
    @Select({"<script>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId == 1 or leadDataRs.subjectsIds == 1 '>",
                    "WITH plan_tb as ( ",
                    "SELECT t1.id,t1.student_id ",
                    "FROM record_course as t1 ",
                    "LEFT JOIN cha_study_plan AS t2 ON t1.student_id = t2.student_id AND t1.year_part = t2.year_part AND t1.`quarter` = t2.quarter_num AND t2.lesson_type = ${lessonType} and t1.lesson_num = t2.lesson_num AND ( t2.subjects_id IN ( ${subjectsId} ) OR t2.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND date(t2.created_at) &lt; '${planEndDate}' AND t2.category_id = 1 ",
                    "WHERE t1.year_part = ${yearPart} AND t1.`quarter` = ${quarterNum} and t1.lesson_num &lt;= ${tastMaxLessonNum} AND ( t1.subjects_id IN ( ${subjectsId} ) OR t1.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND t1.lesson_type = 1 AND (( t1.`status` = 1 ) OR ( t1.`status` = 3 ) OR ( t1.`status` = 2 AND t1.is_deduct_house = 1 AND t1.is_deduct_money = 1 )) AND t1.deleted = 0 AND t2.id IS NULL AND t1.end_date_time &lt; NOW() ",
                    "GROUP BY student_id",
                    ") ",
                "</if>",
                "<if test=' (subjectsId == 2 or leadDataRs.subjectsIds == 2) or (subjectsId == 3 or leadDataRs.subjectsIds == 3) '>",
                "WITH plan_tb as ( ",
                "SELECT",
                    "t1.id,",
                    "t3.student_id,",
                    "count( * ) AS all_count,",
                    "SUM( CASE WHEN t2.id IS NOT NULL THEN 1 ELSE 0 END ) AS pass_count ",
                    "FROM",
                    "( SELECT * FROM ",
                    "<if test='subjectsId == 2 or leadDataRs.subjectsIds == 2'>",
                    "math_db.edu_task",
                    "</if>",
                    "<if test='subjectsId == 3 or leadDataRs.subjectsIds == 3'>",
                    "physics_db.edu_task",
                    "</if>",
                    " WHERE year_part =  ${yearPart} AND `quarter_num` = ${quarterNum} AND task_course_num &lt;= ${tastMaxLessonNum} GROUP BY year_class_id, task_course_num ) AS t1",
                    "INNER JOIN ",
                    "math_db.per_student_account",
                    " AS t3 ON t1.year_part = t3.year_part ",
                    "AND t1.quarter_num = t3.quarter_num ",
                    "AND t1.year_class_id = t3.year_class_id",
                    "LEFT JOIN cha_study_plan AS t2 ON t3.year_part = t2.year_part ",
                    "AND t3.`quarter_num` = t2.quarter_num ",
                    "AND t3.student_id = t2.student_id ",
                    "AND t2.lesson_type = 3 ",
                    "AND t1.task_course_num = t2.lesson_num ",
                    "AND ( t2.subjects_id IN ( ${subjectsId} ) OR t2.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND date(t2.created_at) &lt; '${planEndDate}'",
                    "AND t2.category_id = 1 ",
                    "WHERE",
                    "t1.year_part = ${yearPart} ",
                    "AND t1.`quarter_num` = ${quarterNum} ",
                    "GROUP BY",
                    "t3.student_id ",
                    "HAVING",
                    "(",
                    "all_count &gt; pass_count",
                    ") ",
                ") ",
                "</if>",
            "</when>",


            "SELECT",
            "*,(student_all_count - arrived_count ) AS no_arrived_count,( late_count + no_arrived_count_child ) AS tardiness_rate_count ",
            "FROM",
            "(",
            "SELECT",
            "<if test= 'type == 6'>",
            "sum( CASE WHEN t02.course_type &lt;&gt; 7 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
            "and t02.time_start &gt;=#{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
            "and t02.time_end &lt;=#{timeEnd}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS student_all_count, ",

            "sum( CASE WHEN t02.`status` = 1 AND t02.course_type &lt;&gt; 7 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
            "and t02.time_start &gt;=#{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
            "and t02.time_end &lt;=#{timeEnd}",
            "</when>",
            " THEN 1 ELSE 0 END ) AS arrived_count,",

            "sum( CASE WHEN t02.`status` = 2 AND t02.course_type &lt;&gt; 7 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
            "and t02.time_start &gt;=#{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
            "and t02.time_end &lt;=#{timeEnd}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS leave_count,",

            "sum( CASE WHEN t02.course_type = 7 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
            "and t02.time_start &gt;=#{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
            "and t02.time_end &lt;=#{timeEnd}",
            "</when>",
            " THEN 1 ELSE 0 END ) AS temporary_arrived_count,",

            "COUNT( DISTINCT CASE WHEN t02.student_id AND t02.`status` = 1 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
            "and t02.time_start &gt;=#{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
            "and t02.time_end &lt;=#{timeEnd}",
            "</when>",
            "THEN t02.student_id END ) AS is_call_count,",

            "sum( CASE WHEN t02.`status` = 3 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
            "and t02.time_start &gt;=#{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
            "and t02.time_end &lt;=#{timeEnd}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS truancy_count,",

            "sum( CASE WHEN (`reach_type` = 2 OR t02.`status` IN ( 2, 3 )) AND course_type &lt;&gt; 7  ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
            "and t02.time_start &gt;=#{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
            "and t02.time_end &lt;=#{timeEnd}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS late_count,",

            "sum( CASE WHEN t02.teacher_id IS NOT NULL AND t02.`status` IS NULL ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
            "and t02.time_start &gt;=#{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
            "and t02.time_end &lt;=#{timeEnd}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS no_arrived_count_child,",

            "t01.school_id,t01.pid AS schoolPid,",
            "getSchoolName ( t01.school_id ) AS school_name,",

            "</if>",
            "<if test= 'type != 6'>",
            "sum( CASE WHEN course_type &lt;&gt; 7 THEN 1 ELSE 0 END ) AS student_all_count,",
            "sum( CASE WHEN t02.`status` = 1 AND course_type &lt;&gt; 7 THEN 1 ELSE 0 END ) AS arrived_count,",
            "sum( CASE WHEN t02.`status` = 2 AND course_type &lt;&gt; 7 THEN 1 ELSE 0 END ) AS leave_count,",
            "sum( CASE WHEN course_type = 7 THEN 1 ELSE 0 END ) AS temporary_arrived_count,",
            "COUNT( DISTINCT CASE WHEN t02.student_id AND t02.`status` = 1 THEN t02.student_id END ) AS is_call_count,",
            "sum( CASE WHEN t02.`status` = 3 THEN 1 ELSE 0 END ) AS truancy_count,",
            "sum( CASE WHEN (`reach_type` = 2 OR t02.`status` IN ( 2, 3 )) AND course_type &lt;&gt; 7 THEN 1 ELSE 0 END ) AS late_count,",// 迟到包含旷课，不包含请假
            "sum( CASE WHEN t02.teacher_id IS NOT NULL AND t02.`status` IS NULL THEN 1 ELSE 0 END ) AS no_arrived_count_child,",
            "t02.school_id,",
            "getSchoolName ( t02.school_id ) AS school_name,",
            "</if>",

            "t02.teacher_id,",
            "teacher_name,",
            "grade_id,",
            "t02.subjects_id, ",
            "t02.lesson_num ",
            "<if test= 'type == 6'>",
            "FROM ",
            "( SELECT * FROM school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t01 ",
            "LEFT JOIN ( ",
            "</if>",
            "<if test= 'type != 6'>",
            "FROM ( ",
            "</if>",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.course_type,",
            "sff0.`name` AS teacher_name,",
            "t1.lesson_num,",
            "t1.school_date,",
            "t1.start_date_time ",
            "FROM",
            "record_course AS t1 ",
            "INNER JOIN grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb AS t7 ON t1.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.subjects_id = t7.subjects_id ",
            "</when>",
            "INNER JOIN (select id,`name` from staff) AS sff0 ON sff0.id = t1.old_teacher_id",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = ${lessonType} ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND ((t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.end_date_time &lt; NOW() ) ",
            "OR ( t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.course_type = 7 )) ",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff0.`name` LIKE '%${name}%'",
            "</when>",

            "UNION ALL",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t6.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type,",
            "sff1.`name` AS teacher_name,",
            "t2.lesson_num,",
            "t2.school_date,",
            "t2.start_date_time ",
            "FROM",
            "${courseSchedulingDetailName} AS t2",
            "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "AND t1.reading_status in(${readingStatus}) ",
            "AND t1.`status` = 1",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb2 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.subjects_id = t7.subjects_id ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId != -1 or leadDataRs.subjectsIds != -1'>",
                    "INNER JOIN plan_tb on t1.student_id = plan_tb.student_id",
                "</if>",
            "</when>",
            "INNER JOIN student_grade AS t6 ON t6.year_part = t1.year_part ",
            "AND t6.`quarter_num` = t1.quarter_num ",
            "AND t6.deleted = t1.deleted ",
            "AND t6.subjects_id = t1.subjects_id ",
            "AND t6.`student_id` = t1.student_id ",
            "AND t6.lesson_type = 1 ",
            "AND t6.reading_status in(${readingStatus}) ",
            "AND t6.`status` = 1",
            "and t2.end_date_time &gt;= t6.created_at",
            "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
            "INNER JOIN staff AS sff1 ON sff1.id = t4.teacher_id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL ",
            "AND t2.end_date_time &gt;= NOW()",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff1.`name` LIKE '%${name}%'",
            "</when>",
            "GROUP BY",
            "t2.id,",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",

            "UNION ALL",

            "SELECT",
            "t2.school_id,",
            "t4.teacher_id AS teacher_id,",
            "t2.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t4.id AS grade_id,",
            "t2.subjects_id,",
            "t2.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type,",
            "sff.`name` AS teacher_name,",
            "t2.lesson_num,",
            "t2.school_date,",
            "t2.start_date_time ",
            "FROM",
            "repair_course AS t2",
            "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb3 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t2.student_id = t7.student_id ",
                "AND t2.subjects_id = t7.subjects_id ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId != -1 or leadDataRs.subjectsIds != -1'>",
                    "INNER JOIN plan_tb on t2.student_id = plan_tb.student_id",
                "</if>",
            "</when>",
            "INNER JOIN staff AS sff ON sff.id = t2.old_teacher_id",
            "INNER JOIN student_grade AS t6 ON t6.year_part = t2.year_part ",
            "AND t6.`quarter_num` = t2.QUARTER ",
            "AND t6.deleted = t2.deleted ",
            "AND t6.subjects_id = t2.subjects_id ",
            "AND t6.`student_id` = t2.student_id ",
            "AND t6.lesson_type = 1 ",
            "AND t6.reading_status in(${readingStatus}) ",
            "AND t6.`status` = 1",
            "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t2.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.deleted = 0 ",
            "AND t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.end_date_time &gt;= NOW()",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.old_teacher_id IS NOT NULL ",
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "<if test= 'type == 6'>",
            ") AS t02 ON t01.school_id = t02.school_id ",
            "</if>",
            "<if test= 'type != 6'>",
            ") AS t02 ",
            "</if>",
            "LEFT JOIN cha_study_plan AS csp ON t02.student_id = csp.student_id ",
            "AND csp.subjects_id = t02.subjects_id ",
            "AND csp.lesson_type = ${lessonType}",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND csp.created_at &lt; t02.start_date_time ",
            "LEFT JOIN grade as gr on t02.grade_id = gr.id ",
            "WHERE",
            "1=1",
            "AND csp.student_id IS NULL ",

            "<if test= 'type != 6'>",

            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t02.subjects_id IN (${subjectsId})  ",
            "and t02.school_id in(${schoolIdStr}) ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t02.teacher_id = ${teacherId}",
            "</when>",
            "<when test='authAdminContent.isPerson==1'>",
            "and t02.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t02.teacher_id = ${leadDataRs.teacherId} AND t02.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t02.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---

            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t02.time_start &gt;=#{timeStart} and t02.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t02.time_start &lt;=#{timeEnd} ",
            "</when>",
            "</if>",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t02.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<if test= 'type == 3'>",
                "and t02.teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
            "</if>",
            "GROUP BY",
            "<if test= 'type == 1 or type == 3'>",
            "t02.teacher_id",
            "</if>",
            "<if test= 'type == 2'>",
            "t02.school_id,t02.teacher_id",
            "</if>",
            "<if test= 'type == 4 or type == 6'>",
            "t02.school_id",
            "</if>",
            ") AS tt2",
            "</script>"})
    public abstract List<ArrivalRate> reachRate(@Param("schoolIdStr") String schoolIdStr,
                                                @Param("yearPart") String yearPart,
                                                @Param("quarterNum") String quarterNum,
                                                @Param("type") String type,
                                                @Param("subjectsId") String subjectsId,
                                                @Param("startDateLast") String startDateLast,
                                                @Param("endDateLast") String endDateLast,
                                                @Param("startDate") String startDate,
                                                @Param("endDate") String endDate,
                                                @Param("timeStart") String timeStart,
                                                @Param("timeEnd") String timeEnd,
                                                @Param("lessonType") Integer lessonType,
                                                @Param("radeType") Integer radeType,
                                                @Param("schoolId") String schoolId,
                                                @Param("yearClassId") String yearClassId,
                                                @Param("name") String name,
                                                @Param("teacherId") String teacherId,
                                                @Param("startLessonNum") String startLessonNum,
                                                @Param("endLessonNum") String endLessonNum,
                                                @Param("isRebrush") String isRebrush,
                                                @Param("readingStatus") String readingStatus,
                                                @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                                @Param("dateTimeNow") String dateTimeNow,
                                                @Param("planEndDate") String planEndDate,
                                                @Param("authAdminContent") AuthAdminContent authAdminContent,
                                                @Param("leadDataRs") LeadDataRs leadDataRs,
                                                @Param("tastMaxLessonNum") Integer tastMaxLessonNum
                                                );

    /**
     * 刷题班、智能课 到课率、旷课率详情
     */
    @Select({"<script>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId == 1 or leadDataRs.subjectsIds == 1 '>",
                        "WITH plan_tb as ( ",
                        "SELECT t1.id,t1.student_id ",
                        "FROM record_course as t1 ",
                        "LEFT JOIN cha_study_plan AS t2 ON t1.student_id = t2.student_id AND t1.year_part = t2.year_part AND t1.`quarter` = t2.quarter_num AND t2.lesson_type = ${lessonType} and t1.lesson_num = t2.lesson_num AND ( t2.subjects_id IN ( ${subjectsId} ) OR t2.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND date(t2.created_at) &lt; '${planEndDate}' AND t2.category_id = 1 ",
                        "WHERE t1.year_part = ${yearPart} AND t1.`quarter` = ${quarterNum} AND ( t1.subjects_id IN ( ${subjectsId} ) OR t1.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND t1.lesson_type = 1 AND (( t1.`status` = 1 ) OR ( t1.`status` = 3 ) OR ( t1.`status` = 2 AND t1.is_deduct_house = 1 AND t1.is_deduct_money = 1 )) AND t1.deleted = 0 AND t2.id IS NULL AND t1.end_date_time &lt; NOW() ",
                        "GROUP BY student_id",
                        ") ",
                "</if>",
                "<if test=' (subjectsId == 2 or leadDataRs.subjectsIds == 2) or (subjectsId == 3 or leadDataRs.subjectsIds == 3) '>",
                    "WITH plan_tb as ( ",
                        "SELECT",
                            "t1.id,",
                            "t3.student_id,",
                            "count( * ) AS all_count,",
                            "SUM( CASE WHEN t2.id IS NOT NULL THEN 1 ELSE 0 END ) AS pass_count ",
                            "FROM",
                            "( SELECT * FROM ",
                            "<if test='subjectsId == 2 or leadDataRs.subjectsIds == 2'>",
                            "math_db.edu_task",
                            "</if>",
                            "<if test='subjectsId == 3 or leadDataRs.subjectsIds == 3'>",
                            "physics_db.edu_task",
                            "</if>",
                            " WHERE year_part =  ${yearPart} AND `quarter_num` = ${quarterNum} AND task_course_num &lt;= ${tastMaxLessonNum} GROUP BY year_class_id, task_course_num ) AS t1",
                            "INNER JOIN ",
                            "math_db.per_student_account",
                            " AS t3 ON t1.year_part = t3.year_part ",
                            "AND t1.quarter_num = t3.quarter_num ",
                            "AND t1.year_class_id = t3.year_class_id",
                            "LEFT JOIN cha_study_plan AS t2 ON t3.year_part = t2.year_part ",
                            "AND t3.`quarter_num` = t2.quarter_num ",
                            "AND t3.student_id = t2.student_id ",
                            "AND t2.lesson_type = 3 ",
                            "AND t1.task_course_num = t2.lesson_num ",
                            "AND ( t2.subjects_id IN ( ${subjectsId} ) OR t2.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND date(t2.created_at) &lt; '${planEndDate}'",
                            "AND t2.category_id = 1 ",
                            "WHERE",
                            "t1.year_part = ${yearPart} ",
                            "AND t1.`quarter_num` = ${quarterNum} ",
                            "GROUP BY",
                            "t3.student_id ",
                            "HAVING",
                            "(",
                            "all_count &gt; pass_count",
                            ") ",
                        ") ",
                    "</if>",
            "</when>",

            "SELECT",
            "t.school_id,t.student_id,",
            "getSchoolName ( t.school_id ) AS school_name,",
            "t.teacher_id,",
            "getStaffNameForId ( t.teacher_id ) AS teacher_name,",
            "t.grade_id,",
            "stu.linkman_phone,",
            "t.subjects_id,",
            "(CASE WHEN t.course_type &lt;&gt; 7 THEN IFNULL(t.`status`,4) ELSE 5 END) as `status`,",
            "stu.name as student_name,",
            "gr.name as grade_name,",
            "t.lesson_num,",
            "t.school_date, ",
            "t.scheduling_detail_id,",
            "IFNULL( ssi.in_date_time, ssi.out_date_time ) AS in_date_time ",
            "FROM",
            "(",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.course_type, ",
            "t1.lesson_num,",
            "t1.school_date,",
            "t1.scheduling_detail_id,",
            "t1.start_date_time ",
            "FROM",
            "record_course AS t1 ",
            "INNER JOIN grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb AS t7 ON t1.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.subjects_id = t7.subjects_id ",
            "</when>",
            
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = ${lessonType} ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND ((",
            "t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.end_date_time &lt; NOW() ) OR ( t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.course_type = 7 )) ",

            "UNION ALL ",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t6.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t5.scheduling_detail_id,",
            "t2.start_date_time ",
            "FROM",
            "${courseSchedulingDetailName} AS t2",
            "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "AND t1.reading_status in(${readingStatus}) ",
            "AND t1.`status` = 1",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb2 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.subjects_id = t7.subjects_id ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId != -1 or leadDataRs.subjectsIds != -1'>",
                    "INNER JOIN plan_tb on t1.student_id = plan_tb.student_id",
                "</if>",
            "</when>",
            "INNER JOIN student_grade AS t6 ON t6.year_part = t1.year_part ",
            "AND t6.`quarter_num` = t1.quarter_num ",
            "AND t6.deleted = t1.deleted ",
            "AND t6.subjects_id = t1.subjects_id ",
            "AND t6.`student_id` = t1.student_id ",
            "AND t6.lesson_type = 1 ",
            "AND t6.reading_status in(${readingStatus}) ",
            "AND t6.`status` = 1",
            "and t2.end_date_time &gt;= t6.created_at",
            "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL ",
            "AND t2.end_date_time &gt;= NOW() ",
            "GROUP BY",
            "t2.id,",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",

            "UNION ALL ",

            "SELECT",
            "t2.school_id,",
            "t4.teacher_id AS teacher_id,",
            "t2.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t4.id AS grade_id,",
            "t2.subjects_id,",
            "t2.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t5.scheduling_detail_id, ",
            "t2.start_date_time ",
            "FROM",
            "repair_course AS t2",
            "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb3 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t2.student_id = t7.student_id ",
                "AND t2.subjects_id = t7.subjects_id ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId != -1 or leadDataRs.subjectsIds != -1'>",
                    "INNER JOIN plan_tb on t2.student_id = plan_tb.student_id",
                "</if>",
            "</when>",
            "INNER JOIN student_grade AS t6 ON t6.year_part = t2.year_part ",
            "AND t6.`quarter_num` = t2.QUARTER ",
            "AND t6.deleted = t2.deleted ",
            "AND t6.subjects_id = t2.subjects_id ",
            "AND t6.`student_id` = t2.student_id ",
            "AND t6.lesson_type = 1 ",
            "AND t6.reading_status in(${readingStatus}) ",
            "AND t6.`status` = 1",
            "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t2.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.deleted = 0 ",
            "AND t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.old_teacher_id IS NOT NULL ",
            "AND t2.end_date_time &gt;= NOW() ",
            ") AS t LEFT JOIN student as stu on t.student_id = stu.id ",
            "LEFT JOIN grade as gr on t.grade_id = gr.id ",
            "LEFT JOIN cha_study_plan AS csp ON t.student_id = csp.student_id ",
            "AND csp.subjects_id = t.subjects_id ",
            "AND csp.lesson_type = ${lessonType}",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND csp.created_at &lt; t.start_date_time ",
            "LEFT JOIN student_sign_in AS ssi ON ssi.scheduling_detail_id = t.scheduling_detail_id AND ssi.student_id = t.student_id ",
            "WHERE",
            "1 = 1 ",
            "AND csp.student_id IS NULL",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",

            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "t.subjects_id in(${authAdminContent.subjectsIds})",
            "and gr.year_class_id in(${authAdminContent.yearClassIds})",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t.teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND t.school_id IN (${schoolId}) ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
            "AND t.subjects_id IN (${subjectsId}) ",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and gr.year_class_id in(${yearClassIdStr})",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND t.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---

            "<when test='gradeId!=null and gradeId!=&apos;&apos; '>",
            "AND t.`grade_id` = ${gradeId} ",
            "</when>",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='detailType == 0 '>",// 应到
                "and t.course_type &lt;&gt; 7 ",
            "</when>",
            "<when test='detailType == 1 or detailType == 2 '>",// 已到、未到
                "<when test='status!=null and status!=&apos;&apos; and status == 1'>",// 已到
                    "and t.course_type &lt;&gt; 7 and t.status = 1 ",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 2'>",// 未到
                    "and t.course_type &lt;&gt; 7 and (t.status IN (2,3) or t.status is null)",// 未到暂时包含旷课
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 3'>",// 准时
                    "and t.course_type &lt;&gt; 7 and t.status = 1 and t.reach_type = 1 ",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 4'>",// 迟到
                    "and ((t.`reach_type` = 2 OR t.`status` IN (2,3) ) or (t.teacher_id IS NOT NULL AND t.`status` IS NULL)) AND t.course_type &lt;&gt; 7 ",// 迟到暂时包含旷课
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 5'>",// 旷课
                    "and t.`status` = 3 ",
                "</when>",
            "</when>",
            "<when test='detailType == 3 '>",// 临时
                "and t.course_type =7 and t.status=${status}",
            "</when>",
            "<when test='detailType == 4 '>",// 到勤
                "<when test='status!=null and status!=&apos;&apos; and status == 1'>",// 已到
                    "and t.status = 1 ",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 2'>",// 未到
                    "and (t.status = 2 or t.status is null)",
                "</when>",
            "</when>",
            "<when test='isCall == 1 '>",
            "GROUP BY t.student_id ",
            "</when>",
            "</script>"})
    public abstract IPage<RecordCourse> reachRateDetail(IPage<?> page, @Param("schoolId") String schoolId, @Param("subjectsId") String subjectsId, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("startDateLast") String startDateLast, @Param("endDateLast") String endDateLast, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("gradeId") String gradeId, @Param("teacherId") String teacherId, @Param("type") String type, @Param("status") String status, @Param("timeStart") String timeStart, @Param("timeEnd") String timeEnd, @Param("lessonType") Integer lessonType, @Param("rateType") Integer rateType, @Param("isHistory") boolean isHistory, @Param("yearClassIdStr") String yearClassIdStr, @Param("detailType") String detailType, @Param("isCall") String isCall, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("isRebrush") String isRebrush, @Param("readingStatus") String readingStatus, @Param("courseSchedulingDetailName") String courseSchedulingDetailName, @Param("planEndDate") String planEndDate, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs,@Param("tastMaxLessonNum") Integer tastMaxLessonNum);

    /**
     * 刷题班、智能课，到课率、旷课率，战队列表和战队详情
     */
    @Select({"<script>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId == 1 or leadDataRs.subjectsIds == 1 '>",
                        "WITH plan_tb as ( ",
                        "SELECT t1.id,t1.student_id ",
                        "FROM record_course as t1 ",
                        "LEFT JOIN cha_study_plan AS t2 ON t1.student_id = t2.student_id AND t1.year_part = t2.year_part AND t1.`quarter` = t2.quarter_num AND t2.lesson_type = ${lessonType} and t1.lesson_num = t2.lesson_num AND ( t2.subjects_id IN ( ${subjectsId} ) OR t2.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND date(t2.created_at) &lt; '${planEndDate}' AND t2.category_id = 1 ",
                        "WHERE t1.year_part = ${yearPart} AND t1.`quarter` = ${quarterNum} AND ( t1.subjects_id IN ( ${subjectsId} ) OR t1.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND t1.lesson_type = 1 AND (( t1.`status` = 1 ) OR ( t1.`status` = 3 ) OR ( t1.`status` = 2 AND t1.is_deduct_house = 1 AND t1.is_deduct_money = 1 )) AND t1.deleted = 0 AND t2.id IS NULL AND t1.end_date_time &lt; NOW() ",
                        "GROUP BY student_id",
                        ") ",
                "</if>",
                "<if test=' (subjectsId == 2 or leadDataRs.subjectsIds == 2) or (subjectsId == 3 or leadDataRs.subjectsIds == 3) '>",
                        "WITH plan_tb as ( ",
                        "SELECT",
                        "t1.id,",
                        "t3.student_id,",
                        "count( * ) AS all_count,",
                        "SUM( CASE WHEN t2.id IS NOT NULL THEN 1 ELSE 0 END ) AS pass_count ",
                        "FROM",
                        "( SELECT * FROM ",
                        "<if test='subjectsId == 2 or leadDataRs.subjectsIds == 2'>",
                        "math_db.edu_task",
                        "</if>",
                        "<if test='subjectsId == 3 or leadDataRs.subjectsIds == 3'>",
                        "physics_db.edu_task",
                        "</if>",
                        " WHERE year_part =  ${yearPart} AND `quarter_num` = ${quarterNum} AND task_course_num &lt;= ${tastMaxLessonNum} GROUP BY year_class_id, task_course_num ) AS t1",
                        "INNER JOIN ",
                        "math_db.per_student_account",
                        " AS t3 ON t1.year_part = t3.year_part ",
                        "AND t1.quarter_num = t3.quarter_num ",
                        "AND t1.year_class_id = t3.year_class_id",
                        "LEFT JOIN cha_study_plan AS t2 ON t3.year_part = t2.year_part ",
                        "AND t3.`quarter_num` = t2.quarter_num ",
                        "AND t3.student_id = t2.student_id ",
                        "AND t2.lesson_type = 3 ",
                        "AND t1.task_course_num = t2.lesson_num ",
                        "AND ( t2.subjects_id IN ( ${subjectsId} ) OR t2.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND date(t2.created_at) &lt; '${planEndDate}'",
                        "AND t2.category_id = 1 ",
                        "WHERE",
                        "t1.year_part = ${yearPart} ",
                        "AND t1.`quarter_num` = ${quarterNum} ",
                        "GROUP BY",
                        "t3.student_id ",
                        "HAVING",
                        "(",
                        "all_count &gt; pass_count",
                        ") ",
                        ") ",
                "</if>",
                "</when>",

            "SELECT",
            "team_id,team_pid,teacher_id,teacherName,team_name,",
            "SUM( student_all ) AS student_all_count,",
            "SUM( arrived ) AS arrived_count,",
            "SUM( `leave` ) AS leave_count,",
            "SUM(is_call_count) AS is_call_count,",
            "SUM(student_all - arrived ) AS no_arrived_count ,",
            "SUM(temporary_arrived) AS temporary_arrived_count,",
            "SUM( late_count + no_arrived_count_child ) AS tardiness_rate_count ",
            "FROM",
            "(",
            "SELECT",
            "t1.team_name,t1.team_id,t1.team_pid, ",
            "sum( CASE WHEN t.course_type &lt;&gt; 7 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t.subjects_id IN (${subjectsId})  ",
            "and gr.school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND gr.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "THEN 1 ELSE 0 END ) AS student_all,",

            "sum( CASE WHEN t.`status` = 1 AND t.course_type &lt;&gt; 7 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t.subjects_id IN (${subjectsId})  ",
            "and gr.school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND gr.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "THEN 1 ELSE 0 END ) AS arrived,",

            "sum( CASE WHEN t.`status` = 2 AND t.course_type &lt;&gt; 7 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t.subjects_id IN (${subjectsId})  ",
            "and gr.school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND gr.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "THEN 1 ELSE 0 END ) AS `leave`,",

            "sum( CASE WHEN t.course_type = 7 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t.subjects_id IN (${subjectsId})  ",
            "and gr.school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND gr.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='name!=null and name!=&apos;&apos; '>",
            "and sff.`name` LIKE '%${name}%'",
            "</when>",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "THEN 1 ELSE 0 END ) AS temporary_arrived,",

            "COUNT( DISTINCT CASE WHEN t.student_id AND t.`status` = 1 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t.subjects_id IN (${subjectsId})  ",
            "and gr.school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND gr.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "THEN t.student_id END ) AS is_call_count,",

            "sum( CASE WHEN t.`status` = 3 ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t.subjects_id IN (${subjectsId})  ",
            "and gr.school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND gr.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "THEN 1 ELSE 0 END ) AS truancy_count,",

            "sum( CASE WHEN (t.`reach_type` = 2 OR t.`status` IN ( 2, 3 )) AND t.course_type &lt;&gt; 7  ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t.subjects_id IN (${subjectsId})  ",
            "and gr.school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND gr.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "THEN 1 ELSE 0 END ) AS late_count,",

            "sum( CASE WHEN t.teacher_id IS NOT NULL AND t.`status` IS NULL ",
            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "and ((",
            "gr.year_class_id in (${yearClassId}) ",
            "and t.subjects_id IN (${subjectsId})  ",
            "and gr.school_id in(${schoolIdStr}) ",
            "<when test='authAdminContent.isPerson==1'>",
            "and t.teacher_id = ${authAdminContent.teacherId} ",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND gr.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---

            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
            "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
            "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "THEN 1 ELSE 0 END ) AS no_arrived_count_child,",

            "t1.sourse_id AS teacher_id,",
            "sff.`name` AS teacherName, ",
            "t.lesson_num, ",
            "t.school_date ",

            "FROM",
            "( ",
            "SELECT ",
            "td.*,td.sourse_id as teacher_id ,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
            "FROM ",
            "track_market AS tm ",
            "LEFT JOIN track_detail AS td ON tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "<when test='teamId!=null and teamId!=&apos;&apos;'>",
            "AND tm.id IN (${teamId})",
            "</when>",
            "GROUP BY ",
            "tm.id,td.sourse_id ",
            ") AS t1 ",
            "LEFT JOIN (select id,`name` from staff) AS sff ON sff.id = t1.sourse_id",
            "LEFT JOIN (",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.course_type, ",
            "t1.lesson_num,",
            "t1.school_date, ",
            "t1.start_date_time ",
            "FROM",
            "record_course AS t1 ",
            "INNER JOIN grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb AS t7 ON t1.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.subjects_id = t7.subjects_id ",
            "</when>",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = ${lessonType} ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND ((t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.end_date_time &lt; NOW() ) ",
            "OR ( t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.course_type = 7 )) ",

            "UNION ALL",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t6.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t2.start_date_time ",
            "FROM",
            "${courseSchedulingDetailName} AS t2",
            "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "AND t1.reading_status in(${readingStatus}) ",
            "AND t1.`status` = 1",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb2 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.subjects_id = t7.subjects_id ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId != -1 or leadDataRs.subjectsIds != -1'>",
                    "INNER JOIN plan_tb on t1.student_id = plan_tb.student_id",
                "</if>",
            "</when>",
            "INNER JOIN student_grade AS t6 ON t6.year_part = t1.year_part ",
            "AND t6.`quarter_num` = t1.quarter_num ",
            "AND t6.deleted = t1.deleted ",
            "AND t6.subjects_id = t1.subjects_id ",
            "AND t6.`student_id` = t1.student_id ",
            "AND t6.lesson_type = 1 ",
            "AND t6.reading_status in(${readingStatus}) ",
            "AND t6.`status` = 1",
            "and t2.end_date_time &gt;= t6.created_at",
            "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.deleted = 0 ",
            "AND t2.end_date_time &gt;= NOW()",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL ",
            "GROUP BY",
            "t2.id,",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",

            "UNION ALL ",

            "SELECT",
            "t2.school_id,",
            "t4.teacher_id AS teacher_id,",
            "t2.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t4.id AS grade_id,",
            "t2.subjects_id,",
            "t2.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t2.start_date_time ",
            "FROM",
            "repair_course AS t2",
            "INNER JOIN grade AS t10 ON t2.grade_id = t10.id ",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb3 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t2.student_id = t7.student_id ",
                "AND t2.subjects_id = t7.subjects_id ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId != -1 or leadDataRs.subjectsIds != -1'>",
                    "INNER JOIN plan_tb on t2.student_id = plan_tb.student_id",
                "</if>",
            "</when>",
            "INNER JOIN student_grade AS t6 ON t6.year_part = t2.year_part ",
            "AND t6.`quarter_num` = t2.QUARTER ",
            "AND t6.deleted = t2.deleted ",
            "AND t6.subjects_id = t2.subjects_id ",
            "AND t6.`student_id` = t2.student_id ",
            "AND t6.lesson_type = 1 ",
            "AND t6.reading_status in(${readingStatus}) ",
            "AND t6.`status` = 1",
            "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t2.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.deleted = 0 ",
            "AND t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.end_date_time &gt;= NOW()",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.old_teacher_id IS NOT NULL ",
            ") AS t ON t.teacher_id = t1.sourse_id ",
            "AND ( find_in_set( t.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "AND ( find_in_set( t.grade_id, t1.grade_id_str ) OR t1.grade_id_str = '' ) ",
            "LEFT JOIN cha_study_plan AS csp ON t.student_id = csp.student_id ",
            "AND csp.subjects_id = t.subjects_id ",
            "AND csp.lesson_type = ${lessonType}",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND csp.created_at &lt; t.start_date_time ",
            "LEFT JOIN grade as gr on t.grade_id = gr.id ",
            "WHERE",
            "1=1",
            "AND csp.student_id IS NULL",
            "<when test='teamId!=null and teamId!=&apos;&apos;'>",
            "and t1.team_id IN (${teamId})",
            "</when>",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
            "and t.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "GROUP BY t.teacher_id,t1.team_id ",
            ") AS tt2",
            "GROUP BY team_id",
            "<when test='isTeamDetails!=null and isTeamDetails!=&apos;&apos; and isTeamDetails == 1'>",
            ",teacher_id",
            "</when>",
            "</script>"})
    public abstract List<ArrivalRate> reachRateTeam(@Param("schoolIdStr") String schoolIdStr, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("subjectsId") String subjectsId, @Param("startDateLast") String startDateLast, @Param("endDateLast") String endDateLast, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("timeStart") String timeStart, @Param("timeEnd") String timeEnd, @Param("lessonType") Integer lessonType, @Param("yearClassId") String yearClassId, @Param("isTeamDetails") String isTeamDetails, @Param("classify") String classify, @Param("trackType") String trackType, @Param("teamId") String teamId, @Param("name") String name, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("isRebrush") String isRebrush, @Param("readingStatus") String readingStatus, @Param("courseSchedulingDetailName") String courseSchedulingDetailName, @Param("planEndDate") String planEndDate, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs,
                                                    @Param("tastMaxLessonNum") Integer tastMaxLessonNum);

    /**
     * 刷题班、智能课，到课率、旷课率战队详情
     */
    @Select({"<script>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId == 1 or leadDataRs.subjectsIds == 1 '>",
                        "WITH plan_tb as ( ",
                        "SELECT t1.id,t1.student_id ",
                        "FROM record_course as t1 ",
                        "LEFT JOIN cha_study_plan AS t2 ON t1.student_id = t2.student_id AND t1.year_part = t2.year_part AND t1.`quarter` = t2.quarter_num AND t2.lesson_type = ${lessonType} and t1.lesson_num = t2.lesson_num AND ( t2.subjects_id IN ( ${subjectsId} ) OR t2.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND date(t2.created_at) &lt; '${planEndDate}' AND t2.category_id = 1 ",
                        "WHERE t1.year_part = ${yearPart} AND t1.`quarter` = ${quarterNum} AND ( t1.subjects_id IN ( ${subjectsId} ) OR t1.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND t1.lesson_type = 1 AND (( t1.`status` = 1 ) OR ( t1.`status` = 3 ) OR ( t1.`status` = 2 AND t1.is_deduct_house = 1 AND t1.is_deduct_money = 1 )) AND t1.deleted = 0 AND t2.id IS NULL AND t1.end_date_time &lt; NOW() ",
                        "GROUP BY student_id",
                        ") ",
                "</if>",
            "<if test=' (subjectsId == 2 or leadDataRs.subjectsIds == 2) or (subjectsId == 3 or leadDataRs.subjectsIds == 3) '>",
            "WITH plan_tb as ( ",
            "SELECT",
            "t1.id,",
            "t3.student_id,",
            "count( * ) AS all_count,",
            "SUM( CASE WHEN t2.id IS NOT NULL THEN 1 ELSE 0 END ) AS pass_count ",
            "FROM",
            "( SELECT * FROM ",
            "<if test='subjectsId == 2 or leadDataRs.subjectsIds == 2'>",
            "math_db.edu_task",
            "</if>",
            "<if test='subjectsId == 3 or leadDataRs.subjectsIds == 3'>",
            "physics_db.edu_task",
            "</if>",
            " WHERE year_part =  ${yearPart} AND `quarter_num` = ${quarterNum} AND task_course_num &lt;= ${tastMaxLessonNum} GROUP BY year_class_id, task_course_num ) AS t1",
            "INNER JOIN ",
            "math_db.per_student_account",
            " AS t3 ON t1.year_part = t3.year_part ",
            "AND t1.quarter_num = t3.quarter_num ",
            "AND t1.year_class_id = t3.year_class_id",
            "LEFT JOIN cha_study_plan AS t2 ON t3.year_part = t2.year_part ",
            "AND t3.`quarter_num` = t2.quarter_num ",
            "AND t3.student_id = t2.student_id ",
            "AND t2.lesson_type = 3 ",
            "AND t1.task_course_num = t2.lesson_num ",
            "AND ( t2.subjects_id IN ( ${subjectsId} ) OR t2.subjects_id IN ( ${leadDataRs.subjectsIds} )) AND date(t2.created_at) &lt; '${planEndDate}'",
            "AND t2.category_id = 1 ",
            "WHERE",
            "t1.year_part = ${yearPart} ",
            "AND t1.`quarter_num` = ${quarterNum} ",
            "GROUP BY",
            "t3.student_id ",
            "HAVING",
            "(",
            "all_count &gt; pass_count",
            ") ",
            ") ",
            "</if>",
            "</when>",

            "SELECT",
            "t.school_id,t.student_id,",
            "getSchoolName ( t.school_id ) AS school_name,",
            "t.teacher_id,",
            "getStaffNameForId ( t.teacher_id ) AS teacher_name,",
            "t.grade_id,",
            "stu.linkman_phone,",
            "t.subjects_id,",
            "(CASE WHEN t.course_type &lt;&gt; 7 THEN IFNULL(t.`status`,4) ELSE 5 END) as `status`,",
            "stu.name as student_name,",
            "gr.name as grade_name,",
            "t.lesson_num,",
            "t.school_date, ",
            "t.scheduling_detail_id,",
            "IFNULL( ssi.in_date_time, ssi.out_date_time ) AS in_date_time ",
            "FROM",
            "( ",
            "SELECT ",
            "td.*,tm.teacher_id,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
            "FROM ",
            "track_market AS tm ",
            "LEFT JOIN track_detail AS td ON tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "AND tm.id = ${teamId} ",
            "AND td.sourse_id = ${teacherId} ",
            "GROUP BY ",
            "tm.id,td.sourse_id ",
            ") AS t1 ",
            "INNER JOIN (",
            "SELECT",
            "t1.school_id,",
            "t1.old_teacher_id AS teacher_id,",
            "t1.student_id,",
            "t1.`status`,",
            "t1.reach_type,",
            "t1.old_grade_id AS grade_id,",
            "t1.subjects_id,",
            "t1.year_class_id,",
            "t1.time_start,",
            "t1.time_end,",
            "t1.course_type, ",
            "t1.lesson_num,",
            "t1.school_date, ",
            "t1.scheduling_detail_id, ",
            "t1.start_date_time ",
            "FROM",
            "record_course AS t1 ",
            "INNER JOIN grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb AS t7 ON t1.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.subjects_id = t7.subjects_id ",
            "</when>",
            "WHERE",
            "t1.deleted = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarterNum} ",
            "AND t1.`lesson_type` = ${lessonType} ",
            "AND t1.old_teacher_id IS NOT NULL ",
            "AND ((",
            "t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.end_date_time &lt; NOW() ) OR ( t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.course_type = 7 )) ",

            "UNION ALL ",

            "SELECT",
            "t4.school_id,",
            "t4.teacher_id,",
            "t1.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t6.grade_id,",
            "t2.subjects_id,",
            "t4.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t5.scheduling_detail_id, ",
            "t2.start_date_time ",
            "FROM",
            "${courseSchedulingDetailName} AS t2",
            "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
            "AND t2.`quarter` = t1.quarter_num ",
            "AND t2.deleted = t1.deleted ",
            "AND t2.grade_id = t1.grade_id ",
            "AND t2.lesson_type = t1.lesson_type ",
            "AND t1.reading_status in(${readingStatus}) ",
            "AND t1.`status` = 1",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb2 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t1.student_id = t7.student_id ",
                "AND t1.subjects_id = t7.subjects_id ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId != -1 or leadDataRs.subjectsIds != -1'>",
                    "INNER JOIN plan_tb on t1.student_id = plan_tb.student_id",
                "</if>",
            "</when>",
            "INNER JOIN student_grade AS t6 ON t6.year_part = t1.year_part ",
            "AND t6.`quarter_num` = t1.quarter_num ",
            "AND t6.deleted = t1.deleted ",
            "AND t6.subjects_id = t1.subjects_id ",
            "AND t6.`student_id` = t1.student_id ",
            "AND t6.lesson_type = 1 ",
            "AND t6.reading_status in(${readingStatus}) ",
            "AND t6.`status` = 1",
            "and t2.end_date_time &gt;= t6.created_at",
            "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
            "AND t3.student_id = t1.student_id",
            "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t1.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.deleted = 0 ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t3.id IS NULL ",
            "AND t2.end_date_time &gt;= NOW() ",
            "GROUP BY",
            "t2.id,",
            "t1.school_id,",
            "t1.subjects_id,",
            "t1.student_id,",
            "t1.lesson_type ",

            "UNION ALL ",

            "SELECT",
            "t2.school_id,",
            "t4.teacher_id AS teacher_id,",
            "t2.student_id,",
            "t5.`status`,",
            "t5.reach_type,",
            "t4.id AS grade_id,",
            "t2.subjects_id,",
            "t2.year_class_id,",
            "t2.time_start,",
            "t2.time_end,",
            "1 AS course_type, ",
            "t2.lesson_num,",
            "t2.school_date, ",
            "t5.scheduling_detail_id, ",
            "t2.start_date_time ",
            "FROM",
            "repair_course AS t2",
            "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
            "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                "INNER JOIN again_brush_data_temp_tb3 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                "AND t2.student_id = t7.student_id ",
                "AND t2.subjects_id = t7.subjects_id ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId != -1 or leadDataRs.subjectsIds != -1'>",
                    "INNER JOIN plan_tb on t2.student_id = plan_tb.student_id",
                "</if>",
            "</when>",
            "INNER JOIN student_grade AS t6 ON t6.year_part = t2.year_part ",
            "AND t6.`quarter_num` = t2.QUARTER ",
            "AND t6.deleted = t2.deleted ",
            "AND t6.subjects_id = t2.subjects_id ",
            "AND t6.`student_id` = t2.student_id ",
            "AND t6.lesson_type = 1 ",
            "AND t6.reading_status in(${readingStatus}) ",
            "AND t6.`status` = 1",
            "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
            "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
            "AND t5.student_id = t2.student_id ",
            "AND t5.deleted = 0 ",
            "WHERE",
            "t2.deleted = 0 ",
            "AND t2.year_part = ${yearPart} ",
            "AND t2.`quarter` = ${quarterNum} ",
            "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "AND t2.`status` &lt;&gt; 2 ",
            "AND t2.lesson_type = ${lessonType} ",
            "AND t2.end_date_time &gt;= NOW() ",
            "AND t2.old_teacher_id IS NOT NULL ",
            ") AS t ON t.teacher_id = t1.sourse_id ",
            "AND ( find_in_set( t.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "AND ( find_in_set( t.grade_id, t1.grade_id_str ) OR t1.grade_id_str = '' ) ",
            "LEFT JOIN student as stu on t.student_id = stu.id ",
            "LEFT JOIN grade as gr on t.grade_id = gr.id ",
            "LEFT JOIN cha_study_plan AS csp ON t.student_id = csp.student_id ",
            "AND csp.subjects_id = t.subjects_id ",
            "AND csp.lesson_type = ${lessonType}",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND csp.created_at &lt; t.start_date_time ",
            "LEFT JOIN student_sign_in AS ssi ON ssi.scheduling_detail_id = t.scheduling_detail_id AND ssi.student_id = t.student_id ",
            "WHERE",
            "t.teacher_id = ${teacherId} ",
            "AND t1.team_id = ${teamId} ",
            "AND csp.student_id IS NULL ",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; and timeEnd!=null and timeEnd!=&apos;&apos;'>",
                "and t.time_start &gt;=#{timeStart} and t.time_end &lt;=#{timeEnd} ",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; and (timeStart==null or timeStart==&apos;&apos;) '>",
                "and t.time_start &lt;=#{timeEnd} ",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos; '>",
                "AND t.`grade_id` = ${gradeId} ",
            "</when>",

            // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
            "AND ((",
            "t.subjects_id in(${authAdminContent.subjectsIds})",
            "and gr.year_class_id in(${authAdminContent.yearClassIds})",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND t.teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND t.school_id IN (${schoolId}) ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
            "AND t.subjects_id IN (${subjectsId}) ",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
            "and gr.year_class_id in(${yearClassIdStr})",
            "</when>",
            ") or (t.teacher_id = ${leadDataRs.teacherId} AND t.school_id IN ( ${leadDataRs.schoolIds} ) AND gr.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t.subjects_id IN ( ${leadDataRs.subjectsIds} ) ))",
            // ---权限数据结束---

            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "and t.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<when test='detailType == 0 '>",// 应到
                "and t.course_type &lt;&gt; 7 ",
            "</when>",
            "<when test='detailType == 1 or detailType == 2 '>",
                "<when test='status!=null and status!=&apos;&apos; and status == 1'>",
                    "and t.course_type &lt;&gt; 7 and t.status=${status}",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 2'>",
                    "and t.course_type &lt;&gt; 7 and (t.status IN (2,3) or t.status is null)",// 未到暂时包含旷课
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 3'>",// 准时
                    "and t.course_type &lt;&gt; 7 and t.status = 1 and t.reach_type = 1 ",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 4'>",// 迟到
                    "and ((t.`reach_type` = 2 OR t.`status` IN (2,3) ) or (t.teacher_id IS NOT NULL AND t.`status` IS NULL)) AND t.course_type &lt;&gt; 7",// 迟到暂时包含旷课
                "</when>",
            "</when>",
            "<when test='detailType == 3 '>",
                "and t.course_type =7 and t.status=${status}",
            "</when>",
            "<when test='detailType == 4 '>",
                "<when test='status!=null and status!=&apos;&apos; and status == 1'>",
                    "and t.status=${status}",
                "</when>",
                "<when test='status!=null and status!=&apos;&apos; and status == 2'>",
                    "and (t.status=${status} or t.status is null)",
                "</when>",
            "</when>",
            "<when test='isCall == 1 '>",
                "GROUP BY t.student_id ",
            "</when>",
            "</script>"})
    public abstract IPage<RecordCourse> reachRateTeamDetail(IPage<?> page, @Param("schoolId") String schoolId, @Param("subjectsId") String subjectsId, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("startDateLast") String startDateLast, @Param("endDateLast") String endDateLast, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("gradeId") String gradeId, @Param("teacherId") String teacherId, @Param("type") String type, @Param("status") String status, @Param("timeStart") String timeStart, @Param("timeEnd") String timeEnd, @Param("lessonType") Integer lessonType, @Param("rateType") Integer rateType, @Param("isHistory") boolean isHistory, @Param("yearClassIdStr") String yearClassIdStr, @Param("detailType") String detailType, @Param("classify") String classify, @Param("trackType") String trackType, @Param("teamId") String teamId, @Param("isCall") String isCall, @Param("startLessonNum") String startLessonNum, @Param("endLessonNum") String endLessonNum, @Param("isRebrush") String isRebrush, @Param("readingStatus") String readingStatus, @Param("courseSchedulingDetailName") String courseSchedulingDetailName, @Param("planEndDate") String planEndDate, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs,@Param("tastMaxLessonNum") Integer tastMaxLessonNum);


    @Select({"<script>",
            "SELECT",
            " rc.school_id as schoolId,rc.teacher_id as teacherId ,rc.school_name as schoolName,rc.teacher_name as teacher, ",
            "SUM( rc.buckle_class_house ) / 3 AS alreadyClass, ",
            "SUM( CASE WHEN o.LEVEL = 1 THEN 20 ELSE 17 END * rc.buckle_class_house / 3 ) AS mayMoney ",
            "FROM",
            "record_course rc",
            "JOIN organization o ON rc.school_id = o.id ",
            "WHERE rc.deleted = 0 AND rc.`status` = 1  AND rc.is_deduct_house = 1 ",
            "<when test='subjectId!=null and subjectId!=&apos;&apos; '>",
            "and rc.subjects_id =${subjectId}",
            "</when>",
            "AND rc.year_part = ${yearPart} ",
            "<when test='quarterNum!=null and quarterNum!=&apos;&apos; '>",
            "AND `rc.quarter` = ${quarterNum} ",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
            "and rc.school_date &gt;= &quot;${startDate}&quot; ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
            "and rc.school_date &lt;= &quot;${endDate}&quot; ",
            "</when>",
            "<if test= 'type == 2 and isSuper != 1'>",
            "and rc.school_id =${schoolId}",
            "</if>",
            "AND o.type = 1 AND o.deleted = 0 AND o.status=1 ",
            "GROUP BY ",
            "<if test= 'type == 2'>",
            "rc.school_id,rc.teacher_id",
            "</if>",
            "<if test= 'type == 4'>",
            "rc.school_id",
            "</if>",
            "</script>"})
    public abstract List<AssignMoney> classHouseMoneyType2AndType4(@Param("schoolId") String schoolId,
                                                                   @Param("subjectId") String subjectId,
                                                                   @Param("yearPart") String yearPart,
                                                                   @Param("quarterNum") String quarterNum,
                                                                   @Param("startDate") String startDate,
                                                                   @Param("endDate") String endDate,
                                                                   @Param("type") String type,
                                                                   @Param("isSuper") String isSuper);

    @Select({"<script>",
            "WITH relevant_staff AS (  ",
            "SELECT staff.id,school_id,o.name AS school_name,staff.`name`  ",
            "FROM staff ",
            "JOIN organization o ON staff.school_id = o.id ",
            "WHERE staff.is_teacher = 1  AND staff.deleted = 0 AND staff.`status` = 1 AND o.type=1 AND o.deleted=0",
            "<if test= 'type == 3'>",
            "AND staff.id IN ( SELECT admin_id FROM role_admin WHERE role_id = 1568160887369994242 )",
            "</if>",
            "),  ",
            "relevant_record_course AS (  ",
            "SELECT teacher_id, school_name, buckle_class_house, school_id, subjects_id, ",
            "SUM(CASE WHEN o.LEVEL = 1 THEN 20 ELSE 17 END * buckle_class_house / 3) OVER (PARTITION BY teacher_id) AS mayMoney,   ",
            "SUM(buckle_class_house) OVER (PARTITION BY teacher_id) / 3 AS alreadyClass  ",
            "FROM record_course rc  ",
            "JOIN organization o ON rc.school_id = o.id  ",
            "WHERE year_part = ${yearPart} ",
            "<when test='quarterNum!=null and quarterNum!=&apos;&apos; '>",
            "AND `quarter` = ${quarterNum} ",
            "</when>",
            "AND o.status=1 AND o.type=1 AND o.deleted=0 ",
            "<if test= 'type == 2 and isSuper != 1'>",
            "and rc.school_id =${schoolId}",
            "</if>",
            "<if test= 'type == 3'>",
            "and teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
            "</if>",
            "<when test='subjectId!=null and subjectId!=&apos;&apos; '>",
            "and rc.subjects_id =${subjectId}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
            "and rc.school_date &gt;= &quot;${startDate}&quot; ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
            "and rc.school_date &lt;= &quot;${endDate}&quot; ",
            "</when>",
            "and rc.deleted = 0 AND rc.`status` = 1  AND rc.is_deduct_house = 1 ",
            ") ",
            "SELECT ",
            "s.school_id AS schoolId,s.id as teacherId, s.school_name AS schoolName,s.name as teacher, r.subjects_id AS subjectsId,",
            "COALESCE(r.alreadyClass, 0) AS alreadyClass, ",
            "COALESCE(r.mayMoney, 0) AS mayMoney ",
            "FROM relevant_staff s ",
            "LEFT JOIN relevant_record_course r ON s.id = r.teacher_id  ",
            "<when test='subjectId!=null and subjectId!=&apos;&apos; '>",
            "WHERE r.subjects_id = ${subjectId} ",
            "</when>",
            "GROUP BY s.id",
            "</script>"})
    public abstract List<AssignMoney> classHouseMoneyType1AndType3(@Param("schoolId") String schoolId,
                                                                   @Param("subjectId") String subjectId,
                                                                   @Param("yearPart") String yearPart,
                                                                   @Param("quarterNum") String quarterNum,
                                                                   @Param("startDate") String startDate,
                                                                   @Param("endDate") String endDate,
                                                                   @Param("type") String type,
                                                                   @Param("isSuper") String isSuper);

    @Select({"<script>",
            "WITH relevant_staff AS (   ",
            "SELECT staff.id,school_id,o.name AS school_name,staff.`name`  ",
            "FROM staff ",
            "JOIN organization o ON staff.school_id = o.id ",
            "WHERE staff.is_teacher = 1  AND staff.deleted = 0 AND staff.`status` = 1 AND o.type=1 AND o.deleted=0",
            "<if test= 'type == 3'>",
            "AND staff.id IN ( SELECT admin_id FROM role_admin WHERE role_id = 1568160887369994242 )",
            "</if>",
            "),  ",
            "relevant_record_course AS (  ",
            "SELECT teacher_id, school_name, buckle_class_house, school_id, subjects_id, ",
            "SUM( CASE WHEN o.LEVEL = 1 THEN 20 ELSE 17 END * buckle_class_house / 3 ) OVER ( PARTITION BY teacher_id, school_id ) AS mayMoney,   ",
            "SUM( buckle_class_house ) OVER ( PARTITION BY teacher_id, school_id ) / 3 AS alreadyClass  ",
            "FROM record_course rc  ",
            "JOIN organization o ON rc.school_id = o.id  ",
            "WHERE year_part = ${yearPart} ",
            "AND o.status=1 AND o.type=1 AND o.deleted=0 ",
            "<when test='quarterNum!=null and quarterNum!=&apos;&apos; '>",
            "AND `quarter` = ${quarterNum} ",
            "</when>",
            "<if test= 'type == 2 and isSuper != 1'>",
            "and rc.school_id =${schoolId}",
            "</if>",
            "<when test='subjectId!=null and subjectId!=&apos;&apos; '>",
            "and rc.subjects_id =${subjectId}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; '>",
            "and rc.school_date &gt;= &quot;${startDate}&quot; ",
            "</when>",
            "<when test='endDate!=null and endDate!=&apos;&apos; '>",
            "and rc.school_date &lt;= &quot;${endDate}&quot; ",
            "</when>",
            "and rc.deleted = 0 AND rc.`status` = 1  AND rc.is_deduct_house = 1 ",
            ") ",
            "SELECT ",
            "COALESCE ( r.school_id, s.school_id ) AS schoolId,s.id as teacherId, COALESCE(r.school_name, s.school_name) AS schoolName,s.name as teacher, ",
            "COALESCE(r.alreadyClass, 0) AS alreadyClass, ",
            "COALESCE(r.mayMoney, 0) AS mayMoney ",
            "FROM relevant_staff s ",
            "LEFT JOIN relevant_record_course r ON s.id = r.teacher_id ",
            "<when test='subjectId!=null and subjectId!=&apos;&apos; '>",
            "WHERE r.subjects_id = ${subjectId} ",
            "</when>",
            "GROUP BY s.id, r.school_id",
            "</script>"})
    public abstract List<AssignMoney> classHouseMoneyAdminType2(@Param("schoolId") String schoolId,
                                                                @Param("subjectId") String subjectId,
                                                                @Param("yearPart") String yearPart,
                                                                @Param("quarterNum") String quarterNum,
                                                                @Param("startDate") String startDate,
                                                                @Param("endDate") String endDate,
                                                                @Param("type") String type,
                                                                @Param("isSuper") String isSuper);

    @Select({"<script>",
            "SELECT COUNT(*) AS student_id_course ",
            "FROM (",
            "SELECT  ",
            "a.* ",
            "FROM ",
            "student AS a  ",
            "WHERE ",
            "id IN ( ",
            "SELECT ",
            "b.student_id ",
            "FROM ",
            "student_grade AS b ",
            "WHERE ",
            "b.grade_id IN ( SELECT id FROM grade WHERE quarter_num = ${quarterNum} AND year_part = ${yearPart} ",
            "<if test= 'type == 1 or type == 2 or type == 3'>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND teacher_id = ${teacherId} ",
            "</when>",
            "</if>",
            "<if test= 'type == 2 or type == 4'>",
            "AND school_id = ${schoolId} ",
            "</if>",
            "<if test= 'type == 3'>",
            "and teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
            "</if>",
            "AND deleted = 0 AND b.`status` &lt;&gt; 3 AND (reading_status IN ( 1, 2, 4, 5, 6 ) OR ( reading_status = 3 AND use_course_count &gt; 0 ))))",
            ") TOTAL",
            "</script>"})
    public abstract Integer headcount(@Param("schoolId") String schoolId,
                                      @Param("yearPart") String yearPart,
                                      @Param("quarterNum") String quarterNum,
                                      @Param("type") String type,
                                      @Param("isSuper") String isSuper,
                                      @Param("teacherId") String teacherId);

    /**
     * 补课、调课人数
     */
    @Select({"<script>",
            "SELECT COUNT(id) ",
            "FROM repair_course",
            "WHERE deleted = 0",

            "AND `status` = 1 ",
            "AND school_date &gt;= &quot;${startDate} &quot; ",
            "AND school_date &lt;= &quot;${endDate} &quot; ",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND school_id = ${schoolId} ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND teacher_id = ${teacherId} ",
            "</when>",
            "</script>"})
    public abstract Integer getRepairCourse(@Param("schoolId") String schoolId, @Param("teacherId") String teacherId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    /**
     * 补课、调课课时提成
     */
    @Select({"<script>",
            "SELECT SUM( CASE WHEN o.LEVEL = 1 THEN 20 ELSE 17 END * COUNT(*) ) OVER ( PARTITION BY teacher_id ) AS RepairMayMoney ",
            "FROM repair_course",
            "JOIN organization o ON repair_course.school_id = o.id ",
            "WHERE repair_course.deleted = 0",
            "AND repair_course.`status` = 1 ",
            "AND school_date &gt;=  &quot;${startDate} &quot; ",
            "AND school_date &lt;=  &quot;${endDate} &quot; ",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND school_id = ${schoolId} ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND teacher_id = ${teacherId} ",
            "</when>",
            "</script>"})
    public abstract Integer getRepairMayMoney(@Param("schoolId") String schoolId, @Param("teacherId") String teacherId, @Param("startDate") String startDate, @Param("endDate") String endDate);


    /**
     * 请假未补
     */
    @Select({"<script>",
            "SELECT COUNT(id) as leaveLack",
            "FROM record_course",
            "WHERE is_repair &lt;&gt; 1 ",
            "AND `status` = 2 ",
            "AND school_date &gt;=  &quot;${startDate}&quot; ",
            "AND school_date &lt;=  &quot;${endDate}&quot; ",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND school_id = ${schoolId} ",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND teacher_id = ${teacherId} ",
            "</when>",
            "</script>"})
    public abstract Integer getLeaveLack(@Param("schoolId") String schoolId, @Param("teacherId") String teacherId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    /**
     * 排课未上
     */
    @Select({"<script>",
            "SELECT SUM(count) as classesNotScheduled FROM ( ",
            "SELECT COUNT(DISTINCT student_grade.student_id) AS count ",
            "FROM course_scheduling_detail ",
            "LEFT JOIN student_grade ON student_grade.grade_id = course_scheduling_detail.grade_id",
            "WHERE  ",
            "course_scheduling_detail.deleted = 0 and course_scheduling_detail.`status` = 0 ",
            "AND is_last = 1 ",
            "AND course_scheduling_detail.year_part = ${yearPart} ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND course_scheduling_detail.teacher_id = ${teacherId} ",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND course_scheduling_detail.school_id = ${schoolId} ",
            "</when>",
            "AND school_date &gt;=  &quot;${startDate}&quot; ",
            "AND school_date &lt;=  &quot;${endDate}&quot; ",
            "AND student_grade.deleted = 0 ",
            "AND student_grade.`status` = 1 ",
            "GROUP BY course_scheduling_detail.grade_id,course_scheduling_detail.course_id,course_scheduling_detail.school_id",
            ") co ",
            "</script>"})
    public abstract Integer getClassesNotScheduled(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("schoolId") String schoolId, @Param("yearPart") String yearPart, @Param("teacherId") String teacherId);

    /**
     * 缺课未补
     */
    @Select({"<script>",
            "SELECT COUNT(*) as classesVacancy FROM( ",
            "SELECT ",
            "course_scheduling_detail.* ",
            "FROM ",
            "lack_course_log ",
            "LEFT JOIN course_scheduling_always ON course_scheduling_always.id = lack_course_log.scheduling_always_id  ",
            "LEFT JOIN course_scheduling_detail ON  course_scheduling_detail.grade_id = lack_course_log.grade_id ",
            "WHERE ",
            "lack_course_log.deleted = 0 ",
            "AND is_repair &lt;&gt; 1 ",
            "AND course_scheduling_detail.year_part = ${yearPart} ",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
            "AND course_scheduling_detail.teacher_id = ${teacherId} ",
            "</when>",
            "AND course_scheduling_detail.school_date &gt;=  &quot;${startDate} &quot; ",
            "AND course_scheduling_detail.school_date &lt;=  &quot;${endDate} &quot; ",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND course_scheduling_detail.school_id = ${schoolId} ",
            "</when>",
            "GROUP BY course_scheduling_detail.id",
            ") AS lack",
            "</script>"})
    public abstract Integer getClassesVacancy(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("schoolId") String schoolId, @Param("yearPart") String yearPart, @Param("teacherId") String teacherId);

    /**
     * 获取补课人数列表
     */
    @Select({"<script>",
            "select t.*,",

            "<if test= 'type == 6'>",
            "t1.pid AS school_pid,",
            "SUM( CASE WHEN t.id IS NOT NULL ",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and year_class_id in (${yearClassId})",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS all_repair_count,",

            "SUM( CASE WHEN t.school_date BETWEEN #{startDate} AND #{endDate}  ",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and year_class_id in (${yearClassId})",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS repair_count",

            "FROM ",
            "( SELECT * FROM school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t1 ",
            "LEFT JOIN ( ",
            "</if>",

            "<if test= 'type != 6'>",
            "COUNT( id ) AS all_repair_count,",
            "SUM( CASE WHEN school_date BETWEEN #{startDate} AND #{endDate} THEN 1 ELSE 0 END ) AS repair_count ",
            "FROM (",
            "</if>",

            "SELECT",
            "t02.id,",
            "t02.school_id,",
            "t02.school_name,",
            "t02.teacher_id,",
            "t02.old_teacher_id,",
            "t02.teacher_name,",
            "t02.subjects_id,",
            "t04.year_class_id,",
            "t02.school_date",
            "FROM",
            "( SELECT * FROM staff WHERE is_teacher = 1 AND deleted = 0 ) AS t01",
            "LEFT JOIN (",
            "SELECT",
            " * ",
            "FROM",
            "record_course ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND `quarter` = ${quarterNum} ",
            "AND deleted = 0 ",
            "AND course_type IN ( 3,4,5,6 )",
            ") AS t02 ON t01.id = t02.teacher_id ",
            "<if test= 'type != 6'>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id = ${subjectsId}",
            "</when>",
            "</if>",
            "<when test='lessonType!=null and lessonType!=&apos;&apos; '>",
            "AND `lesson_type` = ${lessonType} ",
            "</when>",
            "LEFT JOIN grade as t04 on t02.old_grade_id = t04.id",

            "<if test= 'type != 6 '>",
            ") AS t ",
            "</if>",
            "<if test= 'type == 6 '>",
            ") AS t ON t1.school_id = t.school_id ",
            "</if>",

            "where 1=1 and teacher_id &lt;&gt; old_teacher_id",
            "<if test= 'type == 3'>",
            "and teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242)",
            "</if>",
            "<when test= 'schoolId!=null and schoolId!=&apos;&apos;'>",
            "and school_id in(${schoolId})",
            "</when>",
            "<when test='schoolIdStr!=null and schoolIdStr!=&apos;&apos; and type == 2 and (schoolId == null or schoolId==&apos;&apos; )'>",
            "and school_id in(${schoolIdStr})",
            "</when>",
            "<if test= 'type != 6'>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and year_class_id in (${yearClassId})",
            "</when>",
            "</if>",
            "GROUP BY",
            "<if test= 'type == 1 or type == 3'>",
            "teacher_id",
            "</if>",
            "<if test= 'type == 2'>",
            "school_id,teacher_id",
            "</if>",
            "<if test= 'type == 4 or type == 6'>",
            "t.school_id",
            "</if>",
            "</script>"})
    public abstract List<RepairLessonRs> getRepairLesson(@Param("schoolIdStr") String schoolIdStr, @Param("schoolId") String schoolId, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("type") String type, @Param("subjectsId") String subjectsId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("isHistory") Integer isHistory, @Param("yearClassId") String yearClassId);

    /**
     * 获取补课人数详情
     */
    @Select({"<script>",
            "SELECT",
            "*,",
            "getSubjectsName(subjects_id) as subjects_name,",
            "CASE course_type WHEN 3 THEN '请假补课' WHEN 4 THEN '调课' WHEN 5 THEN '消课' WHEN 6 THEN '缺课补课' END as course_type_name",
            "from (SELECT",
            "t02.id,",
            "t02.school_id,",
            "t02.school_name,",
            "t02.teacher_id,",
            "t02.old_teacher_id,",
            "t02.teacher_name,",
            "t02.subjects_id,",
            "t02.school_date,",
            "t02.time_start,",
            "t02.time_end,",
            "t02.course_type,",
            "t02.old_grade_id,",
            "t02.student_id,",
            "t03.`name` as student_name,",
            "t04.year_class_id,",
            "t04.name as grade_name",
            "FROM",
            "( SELECT * FROM staff WHERE is_teacher = 1 AND deleted = 0 ) AS t01",
            "LEFT JOIN (",
            "SELECT",
            "* ",
            "FROM",
            "record_course ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND `quarter` = ${quarterNum} ",
            "AND deleted = 0 ",
            "AND course_type IN ( 3,4,5,6 )",
            "AND `lesson_type` = ${lessonType} ",
            ") AS t02 ON t01.id = t02.teacher_id ",
            "INNER JOIN student as t03 on t02.student_id = t03.id",
            "LEFT JOIN grade as t04 on t02.old_grade_id = t04.id",
            ") AS t ",
            "WHERE",
            "1 = 1 and teacher_id &lt;&gt; old_teacher_id",
            "<when test='studentName!=null and studentName!=&apos;&apos;'>",
            "and student_name like '%${studentName}%'",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; and type != 4'>",
            "and teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; and (type == 2 or type ==4)'>",
            "and school_id in(${schoolId})",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and old_grade_id = ${gradeId}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; and endDate!=null and endDate!=&apos;&apos;'>",
            "and school_date BETWEEN #{startDate} AND #{endDate}",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and year_class_id in (${yearClassId})",
            "</when>",
            "</script>"})
    public abstract List<RepairLessonRs> getRepairLessonDetail(@Param("schoolId") String schoolId, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("type") String type, @Param("subjectsId") String subjectsId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("teacherId") Long teacherId, @Param("gradeId") String gradeId, @Param("studentName") String studentName, @Param("yearClassId") String yearClassId);

    /**
     * 获取补课人数战队
     */
    @Select({"<script>",
            "select *,",
            "SUM( CASE WHEN t.id IS NOT NULL  ",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and year_class_id in (${yearClassId})",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS all_repair_count,",

            "SUM( CASE WHEN school_date BETWEEN #{startDate} AND #{endDate}  ",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and year_class_id in (${yearClassId})",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and subjects_id=${subjectsId}",
            "</when>",
            "THEN 1 ELSE 0 END ) AS repair_count",

            "FROM (",
            "SELECT ",
            "td.*,td.sourse_id as teacher_id ,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
            "FROM ",
            "track_market AS tm ",
            "LEFT JOIN track_detail AS td ON tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            "AND tm.id IN (${teamId}) ",
            "</when>",
            "GROUP BY ",
            "tm.id,td.sourse_id ",
            ") AS t1 ",
            "LEFT JOIN (",

            "SELECT",
            "t02.id,",
            "t02.school_id,",
            "t02.school_name,",
            "t02.teacher_id,",
            "t02.old_teacher_id,",
            "t02.teacher_name,",
            "t02.subjects_id,",
            "t04.year_class_id,",
            "t02.school_date",
            "FROM",
            "( SELECT * FROM staff WHERE is_teacher = 1 AND deleted = 0 ) AS t01",
            "LEFT JOIN (",
            "SELECT",
            " * ",
            "FROM",
            "record_course ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND `quarter` = ${quarterNum} ",
            "AND deleted = 0 ",
            "AND course_type IN ( 3,4,5,6 )",
            ") AS t02 ON t01.id = t02.teacher_id ",
            "<when test='lessonType!=null and lessonType!=&apos;&apos; '>",
            "AND `lesson_type` = ${lessonType} ",
            "</when>",
            "LEFT JOIN grade as t04 on t02.old_grade_id = t04.id",
            ") AS t ON t.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( t.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "where 1=1 and t.teacher_id &lt;&gt; t.old_teacher_id",
            "GROUP BY ",
            "team_id ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            ",t.teacher_id ",
            "HAVING t.teacher_id IS NOT NULL",
            "</when>",
            "</script>"})
    public abstract List<RepairLessonRs> getRepairLessonTeamList(@Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("type") String type, @Param("subjectsId") String subjectsId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("yearClassId") String yearClassId, @Param("classify") String classify, @Param("trackType") String trackType, @Param("teamId") String teamId);

    /**
     * 获取补课人数战队详情
     */
    @Select({"<script>",
            "SELECT",
            "*,",
            "getSubjectsName(subjects_id) as subjects_name,",
            "CASE course_type WHEN 3 THEN '请假补课' WHEN 4 THEN '调课' WHEN 5 THEN '消课' WHEN 6 THEN '缺课补课' END as course_type_name",

            "FROM (",
            "SELECT ",
            "td.*,td.sourse_id as teacher_id ,tm.team_name,tm.id AS team_id,tm.pid AS team_pid ",
            "FROM ",
            "track_market AS tm ",
            "LEFT JOIN track_detail AS td ON tm.id = td.track_id ",
            "AND tm.deleted = td.deleted ",
            "WHERE ",
            "tm.classify = ${classify} ",
            "AND tm.track_type = ${trackType} ",
            "AND tm.`status` = 1 ",
            "AND tm.deleted = 0 ",
            "AND tm.year_part = ${yearPart} ",
            "AND tm.quarter_num = ${quarterNum} ",
            "<when test='teamId!=null and teamId!=&apos;&apos; '>",
            "AND tm.id IN (${teamId}) ",
            "</when>",
            "GROUP BY ",
            "tm.id,td.sourse_id ",
            ") AS t1 ",
            "LEFT JOIN (",

            "SELECT t02.id,",
            "t02.school_id,",
            "t02.school_name,",
            "t02.teacher_id,",
            "t02.old_teacher_id,",
            "t02.teacher_name,",
            "t02.subjects_id,",
            "t02.school_date,",
            "t02.time_start,",
            "t02.time_end,",
            "t02.course_type,",
            "t02.old_grade_id,",
            "t02.student_id,",
            "t03.`name` as student_name,",
            "t04.year_class_id,",
            "t04.name as grade_name",
            "FROM",
            "( SELECT * FROM staff WHERE is_teacher = 1 AND deleted = 0 ) AS t01",
            "LEFT JOIN (",
            "SELECT",
            "* ",
            "FROM",
            "record_course ",
            "WHERE",
            "year_part = ${yearPart} ",
            "AND `quarter` = ${quarterNum} ",
            "AND deleted = 0 ",
            "AND course_type IN ( 3,4,5,6 )",
            "AND `lesson_type` = ${lessonType} ",
            ") AS t02 ON t01.id = t02.teacher_id ",
            "INNER JOIN student as t03 on t02.student_id = t03.id",
            "LEFT JOIN grade as t04 on t02.old_grade_id = t04.id",
            ") AS t ON t.teacher_id = t1.teacher_id ",
            "AND ( find_in_set( t.year_class_id, t1.year_class_id_str ) OR t1.year_class_id_str = '' ) ",
            "AND ( find_in_set( t.school_id, t1.school_id_str ) OR t1.school_id_str = '' ) ",
            "WHERE",
            "1 = 1 and t.teacher_id &lt;&gt; t.old_teacher_id",
            "<when test='studentName!=null and studentName!=&apos;&apos;'>",
            "and t.student_name like '%${studentName}%'",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
            "and t.subjects_id=${subjectsId}",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos;'>",
            "and t.teacher_id = ${teacherId}",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos;'>",
            "and t.old_grade_id = ${gradeId}",
            "</when>",
            "<when test='startDate!=null and startDate!=&apos;&apos; and endDate!=null and endDate!=&apos;&apos;'>",
            "and t.school_date BETWEEN #{startDate} AND #{endDate}",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
            "and t.year_class_id in (${yearClassId})",
            "</when>",
            "</script>"})
    public abstract List<RepairLessonRs> getRepairLessonTeamDetail(@Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("subjectsId") String subjectsId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("lessonType") Integer lessonType, @Param("teacherId") Long teacherId, @Param("gradeId") String gradeId, @Param("studentName") String studentName, @Param("yearClassId") String yearClassId, @Param("classify") String classify, @Param("trackType") String trackType, @Param("teamId") String teamId);

    /**
     * 课时核对列表（上课记录）
     */
    @Select({"<script>",
            "select * from (",
            "SELECT ",
            "`t1`.`id` AS `id`,",
            "`t1`.`student_id` AS `student_id`,",
            "`t1`.`status` AS `status`,",
            "`t1`.`lesson_type` AS `lesson_type`,",
            "`t1`.`course_type` AS `course_type`,",
            "`t1`.`is_repair` AS `is_repair`,",
            "`t1`.`school_id` AS `school_id`,",
            "`t1`.`school_name` AS `school_name`,",
            "`t1`.`teacher_id` AS `teacher_id`,",
            "`t1`.`teacher_name` AS `teacher_name`,",
            "`t1`.`subjects_id` AS `subjects_id`,",
            "`t1`.`subjects_name` AS `subjects_name`,",
            "`t1`.`school_date` AS `school_date`,",
            "`t1`.`time_start` AS `time_start`,",
            "`t1`.`time_end` AS `time_end`,",
            "`t1`.`buckle_class_house`,",
            "`t1`.`buckle_class_money`,",
            "`t1`.`teacher_get_house` AS `teacher_get_house`,",
            "`t1`.`teacher_get_money` AS `teacher_get_money`,",
            "`t1`.`year_part` AS `year_part`,",
            "`t1`.`quarter` AS `quarter`,",
            "`t1`.`quarter` AS `quarter_num`,",
            "`t1`.`year_and_quarter` AS `year_and_quarter`,",
            "`t1`.`check_type` AS `check_type`,",
            "`t1`.`deleted` AS `deleted`,",
            "`t1`.`old_grade_id` AS `grade_id`,",
            "`t1`.`is_deduct_house` AS `is_deduct_house`,",
            "`t1`.`is_deduct_money` AS `is_deduct_money`,",
            "`t1`.`take_check_type` AS `take_check_type`,",
            "`t2`.`name` AS student_name,",
            "`t3`.`year_class_id`,",
            "`t3`.`name` AS `grade_name` ",
            "FROM ",
            "record_course AS t1",
            "LEFT JOIN student t2 ON t1.student_id = t2.id ",
            "LEFT JOIN grade AS t3 ON t1.old_grade_id = t3.id ",
            "${ew.customSqlSegment}",
            "UNION ALL ",
            "SELECT",
            "`t1`.`id` AS `id`,",
            "`t1`.`student_id` AS `student_id`,",
            "`t1`.`status` AS `status`,",
            "`t1`.`lesson_type` AS `lesson_type`,",
            "`t1`.`course_type` AS `course_type`,",
            "`t1`.`is_repair` AS `is_repair`,",
            "`t1`.`school_id` AS `school_id`,",
            "`t1`.`school_name` AS `school_name`,",
            "`t1`.`teacher_id` AS `teacher_id`,",
            "`t1`.`teacher_name` AS `teacher_name`,",
            "`t1`.`subjects_id` AS `subjects_id`,",
            "`t1`.`subjects_name` AS `subjects_name`,",
            "`t1`.`school_date` AS `school_date`,",
            "`t1`.`time_start` AS `time_start`,",
            "`t1`.`time_end` AS `time_end`,",
            "`t1`.`buckle_class_house`,",
            "`t1`.`buckle_class_money`,",
            "`t1`.`teacher_get_house` AS `teacher_get_house`,",
            "`t1`.`teacher_get_money` AS `teacher_get_money`,",
            "`t1`.`year_part` AS `year_part`,",
            "`t1`.`quarter` AS `quarter`,",
            "`t1`.`quarter` AS `quarter_num`,",
            "`t1`.`year_and_quarter` AS `year_and_quarter`,",
            "`t1`.`check_type` AS `check_type`,",
            "`t1`.`deleted` AS `deleted`,",
            "`t1`.`old_grade_id` AS `grade_id`,",
            "`t1`.`is_deduct_house` AS `is_deduct_house`,",
            "`t1`.`is_deduct_money` AS `is_deduct_money`,",
            "`t1`.`take_check_type` AS `take_check_type`,",
            "`t2`.`name` AS student_name,",
            "t1.year_class_id,",
            "`t4`.`name` AS `grade_name` ",
            "FROM ",
            "record_course AS t1",
            "INNER JOIN (select MAX(id) as id from record_course where year_part = ${yearPart} and `quarter` = ${quarter} and lesson_type =1 and deleted=0 and course_type = 8 GROUP BY student_id,subjects_id) as t5 on t1.id = t5.id",
            "INNER JOIN student t2 ON t1.student_id = t2.id ",
            "LEFT JOIN student_grade AS t3 ON t1.year_part = t3.year_part ",
            "AND t1.`quarter` = t3.quarter_num ",
            "AND t1.subjects_id = t3.subjects_id ",
            "AND t1.student_id = t3.student_id ",
            "AND t1.lesson_type = t3.lesson_type ",
            "AND t1.deleted = t3.deleted ",
            "AND t3.is_last = 1 ",
            "AND t3.`status` &lt;&gt; 3 ",
            "LEFT JOIN grade AS t4 ON t3.grade_id = t4.id  ",
            "WHERE ",
            "t3.id IS NOT NULL ",
            "AND ((t1.check_type = 1 AND t1.school_date BETWEEN '${startDate}' AND '${endDate}') OR t1.check_type = 0 ) ",
            "<when test='status!=null and status!=&apos;&apos; '>",
                "AND t1.status = ${status} ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                "AND t1.subjects_id = ${subjectsId} ",
            "</when>",
            "<when test='yearClassId!=null and yearClassId!=&apos;&apos; '>",
                "AND t4.year_class_id = ${yearClassId} ",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                "AND t1.school_id = ${schoolId} ",
            "</when>",
            "<when test='studentName!=null and studentName!=&apos;&apos; '>",
                "AND t2.name like '%${studentName}%'",
            "</when>",
            "<when test='courseType!=null and courseType!=&apos;&apos; '>",
                "AND t1.course_type = ${courseType} ",
            "</when>",
            "<when test='checkType!=null and checkType!=&apos;&apos; '>",
                "AND t1.check_type = ${checkType} ",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos; '>",
                "AND t1.old_grade_id = ${gradeId} ",
            "</when>",
            "<when test='isOther!=null and isOther!=&apos;&apos; and isOther == 0'>",
                "<when test='staffId!=null and staffId!=&apos;&apos; '>",
                    "AND (t3.id IS NULL OR (t1.teacher_id = t4.teacher_id))",
                "</when>",
            "</when>",
            "<when test='isOther!=null and isOther!=&apos;&apos; and isOther == 1'>",
                "AND t1.teacher_id &lt;&gt; t4.teacher_id ",
                "<when test='staffId!=null and staffId!=&apos;&apos; '>",
                    "AND t4.teacher_id = ${staffId} ",
                "</when>",
            "</when>",
            "<when test='isOther!=null and isOther!=&apos;&apos; and isOther == 2'>",
                "AND t1.teacher_id &lt;&gt; t4.teacher_id ",
                "<when test='staffId!=null and staffId!=&apos;&apos; '>",
                    "AND t1.teacher_id = ${staffId} ",
                "</when>",
            "</when>",
            ") as t",
            "ORDER BY student_id,school_date DESC ",
            "</script>"
    })
    public abstract IPage<StudentClassLogRep> studentClassLog(IPage<StudentClassLogRep> iPage, @Param(Constants.WRAPPER) Wrapper wrapper, @Param("yearPart") String yearPart, @Param("quarter") String quarter, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("status") String status, @Param("schoolId") String schoolId, @Param("yearClassId") String yearClassId, @Param("subjectsId") String subjectsId, @Param("studentName") String studentName, @Param("courseType") String courseType, @Param("checkType") String checkType, @Param("gradeId") String gradeId, @Param("staffId") String staffId, @Param("isOther") String isOther);

    @Select({"<script>",
            "select *, ",
            "CASE WHEN (( attend_check_type = 0 ) OR ( take_check_type = 0 AND teacher_id &lt;&gt; take_teacher_id )) THEN 0 ELSE 1 END AS check_type ",
            "FROM (",
            "SELECT ",
            "`t1`.`id` AS `id`,",
            "`t1`.`student_id` AS `student_id`,",
            "`t1`.`status` AS `status`,",
            "`t1`.`lesson_type` AS `lesson_type`,",
            "`t1`.`course_type` AS `course_type`,",
            "`t1`.`is_repair` AS `is_repair`,",
            "`t1`.`school_id` AS `school_id`,",
            "`t1`.`school_name` AS `school_name`,",
            "`t1`.`teacher_id` AS `teacher_id`,",
            "`t1`.`teacher_name` AS `teacher_name`,",
            "`t1`.`subjects_id` AS `subjects_id`,",
            "`t1`.`subjects_name` AS `subjects_name`,",
            "`t1`.`school_date` AS `school_date`,",
            "`t1`.`time_start` AS `time_start`,",
            "`t1`.`time_end` AS `time_end`,",
            "`t1`.`buckle_class_house`,",
            "`t1`.`buckle_class_money`,",
            "`t1`.`teacher_get_house` AS `teacher_get_house`,",
            "`t1`.`teacher_get_money` AS `teacher_get_money`,",
            "`t1`.`year_part` AS `year_part`,",
            "`t1`.`quarter` AS `quarter`,",
            "`t1`.`quarter` AS `quarter_num`,",
            "`t1`.`year_and_quarter` AS `year_and_quarter`,",
            "`t1`.`check_type` AS `attend_check_type`,",
            "`t1`.`deleted` AS `deleted`,",
            "`t1`.`old_grade_id` AS `grade_id`,",
            "`t1`.`is_deduct_house` AS `is_deduct_house`,",
            "`t1`.`is_deduct_money` AS `is_deduct_money`,",
            "`t2`.`name` AS student_name,",
            "`t3`.`year_class_id`,",
            "`t3`.`name` AS `grade_name`, ",
            "`t1`.`take_check_type`,",
            "`t3`.`teacher_id` AS `take_teacher_id` ",
            "FROM ",
            "record_course AS t1",
            "LEFT JOIN student t2 ON t1.student_id = t2.id ",
            "LEFT JOIN grade AS t3 ON t1.old_grade_id = t3.id ",
            ") as t",
            "${ew.customSqlSegment}",
            "</script>"
    })
    public abstract IPage<StudentClassLogRep> studentClassLogParticulars(IPage<StudentClassLogRep> iPage, @Param(Constants.WRAPPER) Wrapper wrapper);


    @Select({"<script>",
            "select SUM(teacher_get_money) AS teacher_get_money from (",
            "SELECT",
            "`t1`.`id` AS `id`,",
            "`t1`.`student_id` AS `student_id`,",
            "`t1`.`status` AS `status`,",
            "`t1`.`lesson_type` AS `lesson_type`,",
            "`t1`.`course_type` AS `course_type`,",
            "`t1`.`is_repair` AS `is_repair`,",
            "`t1`.`school_id` AS `school_id`,",
            "`t1`.`grade_id` AS `grade_id`,",
            "`t1`.`grade_name` AS `grade_name`,",
            "`t1`.`teacher_id` AS `teacher_id`,",
            "`t1`.`teacher_name` AS `teacher_name`,",
            "`t1`.`subjects_id` AS `subjects_id`,",
            "`t1`.`subjects_name` AS `subjects_name`,",
            "`t1`.`school_date` AS `school_date`,",
            "`t1`.`teacher_get_house` AS `teacher_get_house`,",
            "`t1`.`teacher_get_money` AS `teacher_get_money`,",
            "`t1`.`year_part` AS `year_part`,",
            "`t1`.`quarter` AS `quarter`,",
            "`t1`.`check_type` AS `check_type`,",
            "`t1`.`deleted` AS `deleted`,",
            " t2.name as student_name, ",
            " t3.year_class_id ",
            "FROM",
            "record_course AS t1",
            "LEFT JOIN  student t2 ON t1.student_id = t2.id ",
            "LEFT JOIN grade AS t3 ON t1.old_grade_id = t3.id ",
            ") as t",
            "${ew.customSqlSegment}",
            "</script>"
    })
    public abstract BigDecimal studentClassTeacherGetMoney(@Param(Constants.WRAPPER) Wrapper wrapper);

    /**
     * 课时核对列表
     */
    @Select({"<script>",
            "SELECT t02.*,",
            "COUNT(*) AS student_count,",
            "<if test= 'type == 6 '>",
            "SUM( CASE WHEN check_type = 1 ",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
            "AND t02.subjects_id = ${subjectsId} ",
            "</when>",
            "THEN check_type ELSE 0 END ) AS is_check_count",
            ",t01.pid AS schoolPid ",
            "FROM ",
            "(SELECT * FROM school_quarter WHERE year_part = ${yearPart} AND quarter_num = ${quarterNum} AND deleted = 0) AS t01 ",
            "LEFT JOIN (",
            "</if>",
            "<if test= 'type != 6 '>",
            "SUM( CASE WHEN check_type = 1 THEN check_type ELSE 0 END ) AS is_check_count",
            "FROM (",
            "</if>",
            "SELECT",
            "`t1`.`id` AS `id`,",
            "`t1`.`lesson_type` AS `lesson_type`,",
            "`t1`.`school_id` AS `school_id`,",
            "`t1`.`school_name` AS `school_name`,",
            "`t1`.`teacher_id` AS `teacher_id`,",
            "`t1`.`teacher_name` AS `teacher_name`,",
            "`t1`.`subjects_id` AS `subjects_id`,",
            "`t1`.`school_date` AS `school_date`,",
            "`t1`.`year_part` AS `year_part`,",
            "`t1`.`quarter` AS `quarter`,",
            "`t1`.`check_type` AS `check_type`,",
            "`t1`.`deleted` AS `deleted`,",
            "`t1`.`course_type` AS `course_type`,",
            "`t1`.`is_deduct_house` AS `is_deduct_house` ",
            "FROM",
            "record_course AS t1",
            "<if test= 'type != 6 '>",
            ") as t02",
            "</if>",
            "<if test= 'type == 6 '>",
            ") AS t02 ON t01.school_id = t02.school_id ",
            "</if>",
            "WHERE ",
            "t02.lesson_type = 1 ",
            "AND t02.year_part = ${yearPart}",
            "AND t02.`quarter` = ${quarterNum}",
            "AND t02.deleted = 0 ",
            "AND t02.course_type &lt;&gt; 8 ",
            "AND t02.school_date BETWEEN '${startDate}' AND '${endDate}' ",
            "<if test= 'type != 6 '>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
            "AND t02.subjects_id = ${subjectsId} ",
            "</when>",
            "</if>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "AND t02.school_id IN (${schoolId})",
            "</when>",
            "GROUP BY",
            "<if test= 'type == 1 or type == 3'>",
            "teacher_id",
            "</if>",
            "<if test= 'type == 2'>",
            "school_id,teacher_id",
            "</if>",
            "<if test= 'type == 4 or type == 6 '>",
            "school_id",
            "</if>",
            "</script>"
    })
    public abstract List<StudentClassLogRep> studentClassLogRate(@Param("schoolId") String schoolId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("subjectsId") String subjectsId, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("type") String type);


    /**
     * 课时核对列表
     */
    @Select({"<script>",
            "SELECT",
            "teacher_id,school_id,school_name,subjects_id,",
            "getStaffNameForId(teacher_id) AS teacher_name,",
            "student_count + yet_teach_student_count + not_teach_student_count AS student_count,",
            "is_check_count + yet_teach_student_count AS is_check_count ",
            "FROM ( ",
                "WITH t02 AS ( ",
                "SELECT",
                "t1.id,",
                "t1.lesson_type,",
                "t1.school_id,",
                "t1.school_name,",
                "t1.teacher_id,",
                "t1.teacher_name,",
                "t1.subjects_id,",
                "t1.school_date,",
                "t1.year_part,",
                "t1.`quarter`,",
                "t1.check_type,",
                "t1.take_check_type,",
                "t1.year_class_id,",
                "t1.deleted,",
                "t1.course_type,",
                "t1.is_deduct_house,",
                "t2.teacher_id AS grade_teacher_id ",
                "FROM",
                "record_course AS t1 ",
                "LEFT JOIN grade AS t2 ON t1.old_grade_id = t2.id ",
                "WHERE",
                "t1.lesson_type = 1 ",
                "AND t1.year_part = ${yearPart} ",
                "AND t1.`quarter` = ${quarterNum} ",
                "AND t1.deleted = 0 ",
                "AND t1.course_type &lt;&gt; 8 ",
                "AND t1.school_date BETWEEN '${startDate}' AND '${endDate}' ",
                ")",

                "SELECT",
                "teacher_id,",
                "school_id,",
                "school_name,",
                "subjects_id,",
                "year_class_id,",
                "SUM( student_count ) AS student_count,",
                "SUM( is_check_count ) AS is_check_count,",
                "SUM( yet_teach_student_count ) AS yet_teach_student_count,",
                "SUM( not_teach_student_count ) AS not_teach_student_count ",

                "FROM (",

                    "SELECT ",
                    "teacher_id,",
                    "school_id,",
                    "school_name,",
                    "subjects_id,",
                    "year_class_id,",
                    "COUNT(id) AS student_count,",
                    "SUM( CASE WHEN check_type = 1 THEN 1 ELSE 0 END ) AS is_check_count,",
                    "0 AS yet_teach_student_count,",
                    "0 AS not_teach_student_count ",
                    "FROM",
                    "t02 ",
                    "GROUP BY",
                    "teacher_id,",
                    "school_id,",
                    "subjects_id,",
                    "year_class_id",

                    "UNION ALL",

                    "SELECT",
                    "grade_teacher_id AS teacher_id,",
                    "school_id,",
                    "school_name,",
                    "subjects_id,",
                    "year_class_id,",
                    "0 AS student_count,",
                    "0 AS is_check_count,",
                    "SUM( CASE WHEN take_check_type = 1 THEN 1 ELSE 0 END ) AS yet_teach_student_count,",
                    "SUM( CASE WHEN take_check_type = 0 THEN 1 ELSE 0 END ) AS not_teach_student_count ",
                    "FROM",
                    "t02 ",
                    "WHERE",
                    "grade_teacher_id &lt;&gt; teacher_id ",
                    "GROUP BY",
                    "grade_teacher_id,",
                    "school_id,",
                    "subjects_id,",
                    "year_class_id",
                ") AS t ",
                "WHERE 1=1",
                // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
                "AND ((",
                "year_class_id in(${authAdminContent.yearClassIds})",
                "AND subjects_id in(${authAdminContent.subjectsIds})",
                "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                    "AND subjects_id in ( ${subjectsId} )",
                "</when>",
                "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                    "AND school_id IN (${schoolId})",
                "</when>",
                "<when test='authAdminContent.isPerson==1'>",
                    "and teacher_id = ${authAdminContent.teacherId} ",
                "</when>",
                ") OR (",
                "teacher_id = ${leadDataRs.teacherId} AND school_id IN ( ${leadDataRs.schoolIds} ) AND year_class_id IN ( ${leadDataRs.yearClassIds} ) AND subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
                // ---权限数据结束---
                "<if test= 'type == 3'>",
                    "AND teacher_id in(select admin_id from role_admin where role_id = 1568160887369994242) ",
                "</if>",
                "GROUP BY",
                "<if test= 'type == 1 or type == 3'>",
                    "teacher_id",
                "</if>",
                "<if test= 'type == 2'>",
                    "school_id,teacher_id",
                "</if>",
                "<if test= 'type == 4 or type == 6 '>",
                    "school_id",
                "</if>",
            ") AS tt1 ",
            "</script>"
    })
    public abstract List<StudentClassLogRep> studentClassLogRate2(@Param("schoolId") String schoolId, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("subjectsId") String subjectsId, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("type") String type, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);

    /**
     * 课时核对数据
     *
     * @param iPage
     * @param yearPart   年份
     * @param quarterNum 学期
     * @param startDate  开始日期
     * @param endDate    结束日期
     * @param schoolId   校区id
     * @param subjectsId 科目id
     * @param checkType  核对状态，0未核对，1已核对，空全部
     * @param teacherId  老师id
     * @param lessonType 课程类型
     * @param isRestrict 是否为登录后强制提醒，0否1是
     * @return
     */
    @Select({"<script>",
            "select *, ",
            "CASE WHEN (( attend_check_type = 0 ) OR ( take_check_type = 0 AND teacher_id &lt;&gt; take_teacher_id )) THEN 0 ELSE 1 END AS check_type ",
            "<when test='isRestrict!=null and isRestrict!=&apos;&apos; '>",
                "<when test='isRestrict==1'>",
                    ", SUM(CASE WHEN is_deduct_house &lt;&gt; 0 THEN 1 ELSE 0 END) AS total, ",
                    "MIN(school_date) AS min_school_date,",
                    "MAX( school_date ) AS max_school_date",
                "</when>",
            "</when>",
            "FROM (",
                "SELECT ",
                "`t1`.`id` AS `id`,",
                "`t1`.`student_id` AS `student_id`,",
                "`t1`.`status` AS `status`,",
                "`t1`.`lesson_type` AS `lesson_type`,",
                "`t1`.`course_type` AS `course_type`,",
                "`t1`.`is_repair` AS `is_repair`,",
                "`t1`.`school_id` AS `school_id`,",
                "`t1`.`school_name` AS `school_name`,",
                "`t1`.`teacher_id` AS `teacher_id`,",
                "`t1`.`teacher_name` AS `teacher_name`,",
                "`t1`.`subjects_id` AS `subjects_id`,",
                "`t1`.`subjects_name` AS `subjects_name`,",
                "`t1`.`school_date` AS `school_date`,",
                "`t1`.`time_start` AS `time_start`,",
                "`t1`.`time_end` AS `time_end`,",
                "`t1`.`buckle_class_house`,",
                "`t1`.`buckle_class_money`,",
                "`t1`.`teacher_get_house` AS `teacher_get_house`,",
                "`t1`.`teacher_get_money` AS `teacher_get_money`,",
                "`t1`.`year_part` AS `year_part`,",
                "`t1`.`quarter` AS `quarter`,",
                "`t1`.`quarter` AS `quarter_num`,",
                "`t1`.`year_and_quarter` AS `year_and_quarter`,",
                "`t1`.`check_type` AS `attend_check_type`,",
                "`t1`.`deleted` AS `deleted`,",
                "`t1`.`old_grade_id` AS `grade_id`,",
                "`t1`.`is_deduct_house` AS `is_deduct_house`,",
                "`t1`.`is_deduct_money` AS `is_deduct_money`,",
                "`t2`.`name` AS student_name,",
                "`t3`.`year_class_id`,",
                "`t3`.`name` AS `grade_name`, ",
                "`t1`.`take_check_type`,",
                "`t3`.`teacher_id` AS `take_teacher_id` ",
                "FROM ",
                "record_course AS t1",
                "LEFT JOIN student t2 ON t1.student_id = t2.id ",
                "LEFT JOIN grade AS t3 ON t1.old_grade_id = t3.id ",
                "WHERE 1=1",
                "AND t1.lesson_type = ${lessonType} ",
                "AND t1.deleted = 0 ",
                "AND t1.course_type &lt;&gt; 8 ",
                "<when test='yearPart!=null and yearPart!=&apos;&apos; '>",
                    "AND t1.year_part = ${yearPart} ",
                "</when>",
                    "<when test='quarterNum!=null and quarterNum!=&apos;&apos; '>",
                "AND t1.`quarter` = ${quarterNum} ",
                "</when>",
                "<when test='checkType!=null and checkType!=&apos;&apos; '>",
                    "AND t1.check_type = ${checkType} ",
                "</when>",
                "<when test='startDate!=null and startDate!=&apos;&apos; and endDate!=&apos;&apos; and endDate!=&apos;&apos; '>",
                    "AND t1.school_date BETWEEN '${startDate}' AND '${endDate}' ",
                "</when>",
                "<when test='isRestrict!=null and isRestrict!=&apos;&apos; '>",
                    "<when test='isRestrict==0'>",
                        // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
                        "AND ((",
                        "t1.year_class_id in(${authAdminContent.yearClassIds})",
                        "AND t1.subjects_id in(${authAdminContent.subjectsIds})",
                        "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                        "AND t1.school_id = ${schoolId} ",
                        "</when>",
                        "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                        "AND t1.subjects_id in (${subjectsId}) ",
                        "</when>",
                        "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                        "AND t1.teacher_id = ${teacherId} ",
                        "</when>",
                        ") OR (",
                        "t1.teacher_id = ${leadDataRs.teacherId} AND t1.school_id IN ( ${leadDataRs.schoolIds} ) AND t1.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t1.subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
                        // ---权限数据结束---
                    "</when>",
                    "<when test='isRestrict==1'>",
                    // 未核对第二天强制提醒
                        "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                            "AND t1.teacher_id = ${teacherId} ",
                        "</when>",
                        "AND t1.school_date &lt; curdate() ",
                    "</when>",
                "</when>",

                "UNION ALL ",

                "SELECT ",
                "`t1`.`id` AS `id`,",
                "`t1`.`student_id` AS `student_id`,",
                "`t1`.`status` AS `status`,",
                "`t1`.`lesson_type` AS `lesson_type`,",
                "`t1`.`course_type` AS `course_type`,",
                "`t1`.`is_repair` AS `is_repair`,",
                "`t1`.`school_id` AS `school_id`,",
                "`t1`.`school_name` AS `school_name`,",
                "`t1`.`teacher_id` AS `teacher_id`,",
                "getStaffNameForId( t3.teacher_id ) AS `teacher_name`,",
                "`t1`.`subjects_id` AS `subjects_id`,",
                "`t1`.`subjects_name` AS `subjects_name`,",
                "`t1`.`school_date` AS `school_date`,",
                "`t1`.`time_start` AS `time_start`,",
                "`t1`.`time_end` AS `time_end`,",
                "`t1`.`buckle_class_house`,",
                "`t1`.`buckle_class_money`,",
                "`t1`.`teacher_get_house` AS `teacher_get_house`,",
                "`t1`.`teacher_get_money` AS `teacher_get_money`,",
                "`t1`.`year_part` AS `year_part`,",
                "`t1`.`quarter` AS `quarter`,",
                "`t1`.`quarter` AS `quarter_num`,",
                "`t1`.`year_and_quarter` AS `year_and_quarter`,",
                "`t1`.`check_type` AS `attend_check_type`,",
                "`t1`.`deleted` AS `deleted`,",
                "`t1`.`old_grade_id` AS `grade_id`,",
                "`t1`.`is_deduct_house` AS `is_deduct_house`,",
                "`t1`.`is_deduct_money` AS `is_deduct_money`,",
                "`t2`.`name` AS student_name,",
                "`t3`.`year_class_id`,",
                "`t3`.`name` AS `grade_name`, ",
                "`t1`.`take_check_type`,",
                "`t3`.`teacher_id` AS `take_teacher_id` ",
                "FROM ",
                "record_course AS t1",
                "LEFT JOIN student t2 ON t1.student_id = t2.id ",
                "LEFT JOIN grade AS t3 ON t1.old_grade_id = t3.id ",
                "WHERE 1=1",
                "AND t1.deleted = 0 ",
                "AND t1.course_type &lt;&gt; 8 ",
                "AND t3.teacher_id &lt;&gt; t1.teacher_id ",
                "AND t3.teacher_id IS NOT NULL",
                "AND t1.lesson_type = ${lessonType} ",
                "<when test='yearPart!=null and yearPart!=&apos;&apos; '>",
                    "AND t1.year_part = ${yearPart} ",
                "</when>",
                "<when test='quarterNum!=null and quarterNum!=&apos;&apos; '>",
                    "AND t1.`quarter` = ${quarterNum} ",
                "</when>",
                "<when test='checkType!=null and checkType!=&apos;&apos; '>",
                    "AND t1.take_check_type = ${checkType} ",
                "</when>",
                "<when test='startDate!=null and startDate!=&apos;&apos; and endDate!=&apos;&apos; and endDate!=&apos;&apos; '>",
                    "AND t1.school_date BETWEEN '${startDate}' AND '${endDate}' ",
                "</when>",
                "<when test='isRestrict!=null and isRestrict!=&apos;&apos; '>",
                    "<when test='isRestrict==0'>",
                        // ---权限数据开始，跟自己所带的年级、校区、科目包起来---
                        "AND ((",
                        "t1.year_class_id in(${authAdminContent.yearClassIds})",
                        "AND t1.subjects_id in(${authAdminContent.subjectsIds})",
                        "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                        "AND t1.school_id = ${schoolId} ",
                        "</when>",
                        "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                        "AND t1.subjects_id in (${subjectsId}) ",
                        "</when>",
                        "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                        "AND t3.teacher_id = ${teacherId} ",
                        "</when>",
                        ") OR (",
                        "t3.teacher_id = ${leadDataRs.teacherId} AND t1.school_id IN ( ${leadDataRs.schoolIds} ) AND t1.year_class_id IN ( ${leadDataRs.yearClassIds} ) AND t1.subjects_id IN ( ${leadDataRs.subjectsIds} ))) ",
                        // ---权限数据结束---
                    "</when>",
                    "<when test='isRestrict==1'>",
                        // 未核对第二天强制提醒
                        "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                            "AND t3.teacher_id = ${teacherId} ",
                        "</when>",
                        "AND t1.school_date &lt; curdate() ",
                    "</when>",
                "</when>",
            ") as t",
            "WHERE 1=1",
            "ORDER BY id",
            "</script>"
    })
    public abstract IPage<StudentClassLogRep> studentClassLogParticulars2(IPage<StudentClassLogRep> iPage, @Param("yearPart") String yearPart, @Param("quarterNum") String quarterNum, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("schoolId") String schoolId, @Param("subjectsId") String subjectsId, @Param("checkType") String checkType, @Param("teacherId") String teacherId, @Param("lessonType") String lessonType, @Param("isRestrict") String isRestrict, @Param("authAdminContent") AuthAdminContent authAdminContent, @Param("leadDataRs") LeadDataRs leadDataRs);



    @Select({"<script>",
            "SELECT",
            "* ",
            "FROM",
            "record_course ",
            "WHERE",
            "deleted = 0 ",
            "AND year_part = ${yearPart} ",
            "AND `quarter` = ${quarterNum} ",
            "AND lesson_type = ${lessonType} ",
            "AND `status` = 2 ",
            "AND student_id = ${studentId} ",
            "AND subjects_id = ${subjectsId} ",
            "AND repair_id = 0 ",
            "AND is_deduct_money = 0",
            "ORDER BY school_date asc",
            "limit 1",
            "</script>"})
    public abstract RecordCourse getLeaveData(@Param("yearPart") Integer yearPart,
                                              @Param("quarterNum") Integer quarterNum,
                                              @Param("lessonType") Integer lessonType,
                                              @Param("studentId") Long studentId,
                                              @Param("subjectsId") Long subjectsId
    );

    /**
     * 请假未补数量
     *
     * @param yearPart
     * @param quarterNum
     * @param lessonType
     * @param studentId
     * @param subjectsId
     * @return
     */
    @Select({"<script>",
            "SELECT",
            "count(id) as count",
            "FROM",
            "record_course ",
            "WHERE",
            "deleted = 0 ",
            "AND year_part = ${yearPart} ",
            "AND `quarter` = ${quarterNum} ",
            "AND lesson_type = ${lessonType} ",
            "AND `status` = 2 ",
            "AND student_id = ${studentId} ",
            "AND subjects_id = ${subjectsId} ",
            "AND repair_id = 0 ",
            "AND is_deduct_money = 0",
            "</script>"})
    public abstract Integer getLeaveCount(@Param("yearPart") Integer yearPart,
                                          @Param("quarterNum") Integer quarterNum,
                                          @Param("lessonType") Integer lessonType,
                                          @Param("studentId") Long studentId,
                                          @Param("subjectsId") Long subjectsId
    );

    @Select({"<script>",
            "select COUNT(*) AS total,MIN( school_date ) AS min_school_date,MAX( school_date ) AS max_school_date from (",
            "SELECT ",
            "`t1`.`id` AS `id`,",
            "`t1`.`student_id` AS `student_id`,",
            "`t1`.`status` AS `status`,",
            "`t1`.`lesson_type` AS `lesson_type`,",
            "`t1`.`course_type` AS `course_type`,",
            "`t1`.`is_repair` AS `is_repair`,",
            "`t1`.`school_id` AS `school_id`,",
            "`t1`.`school_name` AS `school_name`,",
            "`t1`.`teacher_id` AS `teacher_id`,",
            "`t1`.`teacher_name` AS `teacher_name`,",
            "`t1`.`subjects_id` AS `subjects_id`,",
            "`t1`.`subjects_name` AS `subjects_name`,",
            "`t1`.`school_date` AS `school_date`,",
            "`t1`.`time_start` AS `time_start`,",
            "`t1`.`time_end` AS `time_end`,",
            "`t1`.`buckle_class_house`,",
            "`t1`.`buckle_class_money`,",
            "`t1`.`teacher_get_house` AS `teacher_get_house`,",
            "`t1`.`teacher_get_money` AS `teacher_get_money`,",
            "`t1`.`year_part` AS `year_part`,",
            "`t1`.`quarter` AS `quarter`,",
            "`t1`.`quarter` AS `quarter_num`,",
            "`t1`.`year_and_quarter` AS `year_and_quarter`,",
            "`t1`.`check_type` AS `check_type`,",
            "`t1`.`deleted` AS `deleted`,",
            "`t1`.`old_grade_id` AS `grade_id`,",
            "`t1`.`is_deduct_house` AS `is_deduct_house`,",
            "`t1`.`is_deduct_money` AS `is_deduct_money`,",
            "t2.NAME AS student_name,",
            "t3.year_class_id,",
            "`t3`.`name` AS `grade_name` ",
            "FROM ",
            "record_course AS t1",
            "LEFT JOIN student t2 ON t1.student_id = t2.id ",
            "LEFT JOIN grade AS t3 ON t1.old_grade_id = t3.id ",
            "${ew.customSqlSegment}",
            "UNION ALL ",
            "SELECT",
            "`t1`.`id` AS `id`,",
            "`t1`.`student_id` AS `student_id`,",
            "`t1`.`status` AS `status`,",
            "`t1`.`lesson_type` AS `lesson_type`,",
            "`t1`.`course_type` AS `course_type`,",
            "`t1`.`is_repair` AS `is_repair`,",
            "`t1`.`school_id` AS `school_id`,",
            "`t1`.`school_name` AS `school_name`,",
            "`t1`.`teacher_id` AS `teacher_id`,",
            "`t1`.`teacher_name` AS `teacher_name`,",
            "`t1`.`subjects_id` AS `subjects_id`,",
            "`t1`.`subjects_name` AS `subjects_name`,",
            "`t1`.`school_date` AS `school_date`,",
            "`t1`.`time_start` AS `time_start`,",
            "`t1`.`time_end` AS `time_end`,",
            "`t1`.`buckle_class_house`,",
            "`t1`.`buckle_class_money`,",
            "`t1`.`teacher_get_house` AS `teacher_get_house`,",
            "`t1`.`teacher_get_money` AS `teacher_get_money`,",
            "`t1`.`year_part` AS `year_part`,",
            "`t1`.`quarter` AS `quarter`,",
            "`t1`.`quarter` AS `quarter_num`,",
            "`t1`.`year_and_quarter` AS `year_and_quarter`,",
            "`t1`.`check_type` AS `check_type`,",
            "`t1`.`deleted` AS `deleted`,",
            "`t1`.`old_grade_id` AS `grade_id`,",
            "`t1`.`is_deduct_house` AS `is_deduct_house`,",
            "`t1`.`is_deduct_money` AS `is_deduct_money`,",
            "t2.NAME AS student_name,",
            "t1.year_class_id,",
            "`t4`.`name` AS `grade_name` ",
            "FROM ",
            "record_course AS t1",
            "INNER JOIN (select MAX(id) as id from record_course where year_part = ${yearPart} and `quarter` = ${quarter} and lesson_type =1 and deleted=0 and course_type = 8 GROUP BY student_id,subjects_id) as t5 on t1.id = t5.id",
            "INNER JOIN student t2 ON t1.student_id = t2.id ",
            "LEFT JOIN student_grade AS t3 ON t1.year_part = t3.year_part ",
            "AND t1.`quarter` = t3.quarter_num ",
            "AND t1.subjects_id = t3.subjects_id ",
            "AND t1.student_id = t3.student_id ",
            "AND t1.lesson_type = t3.lesson_type ",
            "AND t1.deleted = t3.deleted ",
            "AND t3.is_last = 1 ",
            "AND t3.`status` &lt;&gt; 3 ",
            "LEFT JOIN grade AS t4 ON t3.grade_id = t4.id  ",
            "WHERE ",
            "t3.id IS NOT NULL ",
            "AND t1.check_type = 0 ",
            "AND t1.year_part = ${yearPart} ",
            "AND t1.`quarter` = ${quarter} ",
            "AND t1.check_type = 0 ",
            "AND t1.teacher_id = ${staffId} ",
            "AND t1.school_date &lt; curdate() ",
            ") as t",
            "</script>"
    })
    public abstract StudentClassLogRep uncheckedCount(@Param(Constants.WRAPPER) Wrapper wrapper, @Param("yearPart") String yearPart, @Param("quarter") String quarter, @Param("staffId") String staffId);


    @Select("select count(id) as count from student_sign_give where `year_part` = ${yearPart} and quarter_num = ${quarterNum} and '${dateNow}' BETWEEN start_date and end_date")
    public Integer getSignGiveCount(@Param("yearPart") Integer yearPart,
                                    @Param("quarterNum") Integer quarterNum,
                                    @Param("dateNow") String dateNow);

    /**
     * 刷题到勤
     */
    @Select({"<script>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                "<if test=' subjectsId == 1 '>",
                    "WITH plan_tb as ( ",
                    "SELECT t1.id,t1.student_id ",
                    "FROM record_course as t1 ",
                    "LEFT JOIN cha_study_plan AS t2 ON t1.student_id = t2.student_id AND t1.year_part = t2.year_part AND t1.`quarter` = t2.quarter_num AND t2.lesson_type = ${lessonType} and t1.lesson_num = t2.lesson_num AND t2.subjects_id = ${subjectsId} AND date(t2.created_at) &lt; '${planEndDate}' AND t2.category_id = 1 ",
                    "WHERE t1.year_part = ${yearPart} AND t1.`quarter` = ${quarterNum} AND t1.subjects_id = ${subjectsId} AND t1.lesson_type = 1 AND (( t1.`status` = 1 ) OR ( t1.`status` = 3 ) OR ( t1.`status` = 2 AND t1.is_deduct_house = 1 AND t1.is_deduct_money = 1 )) AND t1.deleted = 0 AND t2.id IS NULL AND t1.end_date_time &lt; NOW() ",
                    "GROUP BY student_id",
                    ") ",
                "</if>",
            "</when>",

            "SELECT",
            "t.school_id,t.student_id,",
            "getSchoolName ( t.school_id ) AS school_name,",
            "t.teacher_id,",
            "staff.`name` AS teacher_name,",
            "t.grade_id,",
            "stu.linkman_phone,",
            "t.subjects_id,",
            "t.`status`,",
            "stu.`name` as student_name,",
            "gr.`name` as grade_name,",
            "gr.year_class_id,",
            "t.lesson_num,",
            "t.school_date, ",
            "t.start_date_time, ",
            "t.scheduling_detail_id,",
            "ssi.id as student_sign_in_id,",
            "ssi.in_date_time, ",
            "ssi.out_date_time, ",
            "ssi.brush_date_time ",
            "<if test= 'isCount == 1 '>",
                ",",
                "CASE",
                "WHEN t.`status` IN ( 2, 3 ) OR t.`status` IS NULL THEN '0' ",// 未到校
                "WHEN in_date_time IS NOT NULL AND out_date_time IS NOT NULL THEN TIMESTAMPDIFF(MINUTE, in_date_time, out_date_time) ",// 离校
                "WHEN in_date_time IS NOT NULL AND out_date_time IS NULL AND DATE(in_date_time) = CURDATE() THEN TIMESTAMPDIFF(MINUTE, in_date_time, NOW()) ",// 刷题中
                "WHEN in_date_time IS NOT NULL AND out_date_time IS NULL AND DATE(in_date_time) &lt;&gt; CURDATE() THEN '无效' ",// 无效
                "ELSE '无效' ",
                "END AS in_school_time, ",

                "CASE",
                "WHEN t.`status` IN ( 2, 3 ) OR t.`status` IS NULL THEN '未到校' ",
                "WHEN in_date_time IS NOT NULL AND out_date_time IS NOT NULL THEN '离校' ",
                "WHEN in_date_time IS NOT NULL AND out_date_time IS NULL AND DATE(in_date_time) = CURDATE() THEN '刷题中' ",
                "WHEN in_date_time IS NOT NULL AND out_date_time IS NULL AND DATE(in_date_time) &lt;&gt; CURDATE() THEN '无效' ",
                "ELSE '无效' ",
                "END AS in_school_status ",
            "</if>",

            "<if test= 'isCount == 2 '>",
                ",",
                "SUM( CASE WHEN t.`status` = 1 AND ssi.out_date_time IS NULL AND DATE ( in_date_time ) = CURDATE() THEN 1 ELSE 0 END ) AS in_school_count,",
                "SUM( CASE WHEN (t.`status` = 1 AND ssi.out_date_time IS NOT NULL OR (in_date_time IS NOT NULL AND out_date_time IS NULL AND DATE ( in_date_time ) &lt;&gt; CURDATE())) THEN 1 ELSE 0 END ) AS out_school_count,",
                "SUM( CASE WHEN t.`status` IN ( 2, 3 ) OR  t.`status` IS NULL THEN 1 ELSE 0 END ) AS not_school_count ",
            "</if>",

            "FROM",
            "(",
                "SELECT",
                "t1.school_id,",
                "t1.old_teacher_id AS teacher_id,",
                "t1.student_id,",
                "t1.`status`,",
                "t1.reach_type,",
                "t1.old_grade_id AS grade_id,",
                "t1.subjects_id,",
                "t1.year_class_id,",
                "t1.time_start,",
                "t1.time_end,",
                "t1.course_type, ",
                "t1.lesson_num,",
                "t1.school_date,",
                "t1.scheduling_detail_id,",
                "t1.start_date_time ",
                "FROM",
                "record_course AS t1 ",
                "INNER JOIN grade AS t10 ON t1.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
                "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                    "INNER JOIN again_brush_data_temp_tb AS t7 ON t1.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                    "AND t1.student_id = t7.student_id ",
                    "AND t1.subjects_id = t7.subjects_id ",
                "</when>",
                "WHERE",
                "t1.deleted = 0 ",
                "AND t1.year_part = ${yearPart} ",
                "AND t1.`quarter` = ${quarterNum} ",
                "AND t1.`lesson_type` = ${lessonType} ",
                "AND t1.old_teacher_id IS NOT NULL ",
                "AND (( t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.end_date_time &lt; NOW() ) OR ( t1.school_date BETWEEN '${startDate}' AND '${endDate}' AND t1.course_type = 7 )) ",

                "UNION ALL ",

                "SELECT",
                "t4.school_id,",
                "t4.teacher_id,",
                "t1.student_id,",
                "t5.`status`,",
                "t5.reach_type,",
                "t6.grade_id,",
                "t2.subjects_id,",
                "t4.year_class_id,",
                "t2.time_start,",
                "t2.time_end,",
                "1 AS course_type, ",
                "t2.lesson_num,",
                "t2.school_date, ",
                "t5.scheduling_detail_id, ",
                "t2.start_date_time ",
                "FROM",
                "${courseSchedulingDetailName} AS t2",
                "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
                "INNER JOIN student_grade AS t1 ON t2.year_part = t1.year_part ",
                "AND t2.`quarter` = t1.quarter_num ",
                "AND t2.deleted = t1.deleted ",
                "AND t2.grade_id = t1.grade_id ",
                "AND t2.lesson_type = t1.lesson_type ",
                "AND t1.reading_status in(${readingStatus}) ",
                "AND t1.`status` = 1",
                "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                    "INNER JOIN again_brush_data_temp_tb2 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                    "AND t1.student_id = t7.student_id ",
                    "AND t1.subjects_id = t7.subjects_id ",
                "</when>",
                "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                    "<if test=' subjectsId == 1 '>",
                        "INNER JOIN plan_tb on t1.student_id = plan_tb.student_id",
                    "</if>",
                "</when>",
                "INNER JOIN student_grade AS t6 ON t6.year_part = t1.year_part ",
                "AND t6.`quarter_num` = t1.quarter_num ",
                "AND t6.deleted = t1.deleted ",
                "AND t6.subjects_id = t1.subjects_id ",
                "AND t6.`student_id` = t1.student_id ",
                "AND t6.lesson_type = 1 ",
                "AND t6.reading_status in(${readingStatus}) ",
                "AND t6.`status` = 1",
                "and t2.end_date_time &gt;= t6.created_at",
                "LEFT JOIN repair_course AS t3 ON t3.out_scheduling_detail_id = t2.id AND t3.deleted = 0",
                "AND t3.student_id = t1.student_id",
                "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
                "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
                "AND t5.student_id = t1.student_id ",
                "AND t5.deleted = 0 ",
                "WHERE",
                "t2.year_part = ${yearPart} ",
                "AND t2.`quarter` = ${quarterNum} ",
                "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
                "AND t2.lesson_type = ${lessonType} ",
                "AND t2.deleted = 0 ",
                "AND t2.`status` &lt;&gt; 2 ",
                "AND t3.id IS NULL ",
                "AND t2.end_date_time &gt;= NOW() ",
                "GROUP BY",
                "t2.id,",
                "t1.school_id,",
                "t1.subjects_id,",
                "t1.student_id,",
                "t1.lesson_type ",

                "UNION ALL ",

                "SELECT",
                "t2.school_id,",
                "t4.teacher_id AS teacher_id,",
                "t2.student_id,",
                "t5.`status`,",
                "t5.reach_type,",
                "t4.id AS grade_id,",
                "t2.subjects_id,",
                "t2.year_class_id,",
                "t2.time_start,",
                "t2.time_end,",
                "1 AS course_type, ",
                "t2.lesson_num,",
                "t2.school_date, ",
                "t5.scheduling_detail_id, ",
                "t2.start_date_time ",
                "FROM",
                "repair_course AS t2",
                "INNER JOIN grade AS t10 ON t2.grade_id = t10.id AND t10.is_rebrush = ${isRebrush} ",
                "<when test= 'isRebrush!=null and isRebrush!=&apos;&apos; and isRebrush == 1'>",
                    "INNER JOIN again_brush_data_temp_tb3 AS t7 ON t2.school_date BETWEEN t7.start_task_date AND t7.end_task_date ",
                    "AND t2.student_id = t7.student_id ",
                    "AND t2.subjects_id = t7.subjects_id ",
                "</when>",
                "<when test='subjectsId!=null and subjectsId!=&apos;&apos;'>",
                    "<if test=' subjectsId == 1 '>",
                        "INNER JOIN plan_tb on t2.student_id = plan_tb.student_id",
                    "</if>",
                "</when>",
                "INNER JOIN student_grade AS t6 ON t6.year_part = t2.year_part ",
                "AND t6.`quarter_num` = t2.QUARTER ",
                "AND t6.deleted = t2.deleted ",
                "AND t6.subjects_id = t2.subjects_id ",
                "AND t6.`student_id` = t2.student_id ",
                "AND t6.lesson_type = 1 ",
                "AND t6.reading_status in(${readingStatus}) ",
                "AND t6.`status` = 1",
                "LEFT JOIN grade AS t4 ON t6.grade_id = t4.id",
                "LEFT JOIN record_course AS t5 ON t5.scheduling_detail_id = t2.id ",
                "AND t5.student_id = t2.student_id ",
                "AND t5.deleted = 0 ",
                "WHERE",
                "t2.deleted = 0 ",
                "AND t2.year_part = ${yearPart} ",
                "AND t2.`quarter` = ${quarterNum} ",
                "AND t2.school_date BETWEEN '${startDate}' AND '${endDate}' ",
                "AND t2.`status` &lt;&gt; 2 ",
                "AND t2.lesson_type = ${lessonType} ",
                "AND t2.old_teacher_id IS NOT NULL ",
                "AND t2.end_date_time &gt;= NOW() ",
            ") AS t ",
            "LEFT JOIN student as stu on t.student_id = stu.id ",
            "LEFT JOIN grade as gr on t.grade_id = gr.id ",
            "LEFT JOIN cha_study_plan AS csp ON t.student_id = csp.student_id ",
            "AND csp.subjects_id = t.subjects_id ",
            "AND csp.lesson_type = ${lessonType}",
            "AND csp.`status` = 1 ",
            "AND csp.year_part = ${yearPart}",
            "AND csp.quarter_num = ${quarterNum} ",
            "AND school_date BETWEEN csp.start_task_date AND csp.end_task_date ",
            "AND csp.created_at &lt; t.start_date_time ",
            "LEFT JOIN student_sign_in AS ssi ON ssi.scheduling_detail_id = t.scheduling_detail_id AND ssi.student_id = t.student_id ",
            "LEFT JOIN staff ON t.teacher_id = staff.id",
            "WHERE",
            "1 = 1 ",
            "AND csp.student_id IS NULL",
            "<when test='timeStart!=null and timeStart!=&apos;&apos; '>",
                "AND t.time_start &gt;= #{timeStart}",
            "</when>",
            "<when test='timeEnd!=null and timeEnd!=&apos;&apos; '>",
                "AND t.time_end &lt;= #{timeEnd}",
            "</when>",
            "<when test='teacherId!=null and teacherId!=&apos;&apos; '>",
                "AND t.teacher_id = ${teacherId}",
            "</when>",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
                "AND t.school_id IN (${schoolId}) ",
            "</when>",
            "<when test='subjectsId!=null and subjectsId!=&apos;&apos; '>",
                "AND t.subjects_id IN ( ${subjectsId} )",
            "</when>",
            "<when test='gradeId!=null and gradeId!=&apos;&apos; '>",
                "AND t.`grade_id` = ${gradeId} ",
            "</when>",
            "<when test='yearClassIdStr!=null and yearClassIdStr!=&apos;&apos; '>",
                "AND gr.year_class_id in (${yearClassIdStr}) ",
            "</when>",
            "<when test='studentName!=null and studentName!=&apos;&apos; '>",
                "AND stu.`name` LIKE '%${studentName}%' ",
            "</when>",
            "<when test='teacherName!=null and teacherName!=&apos;&apos; '>",
                "AND staff.`name` LIKE '%${teacherName}%' ",
            "</when>",
            "<when test='(startLessonNum!=null and startLessonNum!=&apos;&apos;) and (endLessonNum!=null and endLessonNum!=&apos;&apos;)'>",
                "AND t.lesson_num BETWEEN ${startLessonNum} and ${endLessonNum}",
            "</when>",
            "<if test= 'isCount != 2 '>",
                // 统计的学员数据不通过点击的状态查询
                "<when test='status == 1'>",// 在校
                    "AND t.`status` = 1 AND ssi.out_date_time IS NULL AND DATE ( in_date_time ) = CURDATE() ",
                "</when>",
                "<when test='status == 2'>",// 离校
                    "AND (t.`status` = 1 AND ssi.out_date_time IS NOT NULL OR (in_date_time IS NOT NULL AND out_date_time IS NULL AND DATE ( in_date_time ) &lt;&gt; CURDATE()) )",
                "</when>",
                "<when test='status == 3'>",// 未到
                    "AND t.course_type &lt;&gt; 7 and (t.status IN (2,3) or t.status is null) ",
                "</when>",
                "<if test= 'type == 2 '>",
                    "GROUP BY teacher_id",
                "</if>",
                "HAVING 1=1 ",
                "<when test='schoolType == 1'>",// 正常，刷题时长在0-39分钟
                    "AND in_school_time &gt;= 0 AND in_school_time &lt;= 39 ",
                "</when>",
                "<when test='schoolType == 2'>",// 预警，刷题时长在40-89分钟
                    "AND in_school_time &gt;= 40 AND in_school_time &lt;= 89 ",
                "</when>",
                "<when test='schoolType == 3'>",// 超时，刷题时长大于等于90分钟
                    "AND in_school_time &gt;= 90 ",
                "</when>",
                "<when test='schoolType == 4'>",// 写题，有签到时间，没有交卷时间
                    "AND ssi.brush_date_time IS NULL ",
                "</when>",
                "<when test='schoolType == 5'>",// 订正，有签到时间，有交卷时间
                    "AND ssi.brush_date_time IS NOT NULL ",
                "</when>",
                "<when test='schoolType == 6'>",// 超时，小学:总时长大于等于90分钟；初中:总时间大于等于120分钟
                    "AND ((year_class_id &lt; 7 AND year_class_id &gt; 2 AND in_school_time &gt;= 90 ) OR ( year_class_id &lt; 10 AND year_class_id &gt; 6 AND in_school_time &gt;= 120 ))",
                "</when>",
            "</if>",
            "</script>"})
    public abstract List<RecordCourse> getBrushQuestionsDiligently(@Param("schoolId") String schoolId,
                                                                   @Param("subjectsId") String subjectsId,
                                                                   @Param("yearPart") String yearPart,
                                                                   @Param("quarterNum") String quarterNum,
                                                                   @Param("startDateLast") String startDateLast,
                                                                   @Param("endDateLast") String endDateLast,
                                                                   @Param("startDate") String startDate,
                                                                   @Param("endDate") String endDate,
                                                                   @Param("gradeId") String gradeId,
                                                                   @Param("teacherId") String teacherId,
                                                                   @Param("status") String status,
                                                                   @Param("timeStart") String timeStart,
                                                                   @Param("timeEnd") String timeEnd,
                                                                   @Param("lessonType") Integer lessonType,
                                                                   @Param("yearClassIdStr") String yearClassIdStr,
                                                                   @Param("startLessonNum") String startLessonNum,
                                                                   @Param("endLessonNum") String endLessonNum,
                                                                   @Param("isRebrush") String isRebrush,
                                                                   @Param("readingStatus") String readingStatus,
                                                                   @Param("courseSchedulingDetailName") String courseSchedulingDetailName,
                                                                   @Param("isCount") Integer isCount, // 1正常，2计数
                                                                   @Param("studentName") String studentName,
                                                                   @Param("schoolType") String schoolType,
                                                                   @Param("planEndDate") String planEndDate,
                                                                   @Param("teacherName") String teacherName,
                                                                   @Param("type") Integer type
    );

    /**
     * 获取到课
     * @param yearPart
     * @param quarterNum
     * @param studentId
     * @return
     */
    @Select("select count(id) as count from record_course where deleted=0 and year_part = ${yearPart} and `quarter` = ${quarterNum} and lesson_type = 1 and `status`=1 and student_id = ${studentId} and subjects_id = ${subjectsId}")
    public abstract Integer getRecordCountArrive(@Param("yearPart") Integer yearPart,@Param("quarterNum") Integer quarterNum,@Param("studentId") Long studentId,@Param("subjectsId") Long subjectsId);

    @Select({"<script>",
            "SELECT t1.*",
            "FROM ",
            "record_course AS t1 ",
            "INNER JOIN `quarter` AS t2 ON t1.year_part = t2.year_part AND t1.`quarter` = t2.num ",
            "WHERE ",
            "t1.lesson_type = ${lessonType} ",
            "AND t1.student_id = ${studentId} ",
            "AND t1.subjects_id = ${subjectsId} ",
            "AND t1.`status` = 1 ",
            "AND t1.deleted = 0 ",
            "AND t2.id BETWEEN ${startQuarterId} AND ${endQuarterId} ",
            "ORDER BY school_date DESC ",
            "LIMIT 1 ",
            "</script>"})
    public abstract RecordCourse getRecordCourseByLastThreeQuarter(@Param("lessonType") Integer lessonType, @Param("studentId") Long studentId, @Param("subjectsId") String subjectsId, @Param("startQuarterId") Long startQuarterId, @Param("endQuarterId") Long endQuarterId);

}
